Plugin Directory

Changeset 3434874


Ignore:
Timestamp:
01/08/2026 05:55:22 AM (3 months ago)
Author:
akashmalik
Message:

PHP version 8.4 release compatibility

File:
1 edited

Legend:

Unmodified
Added
Removed
  • scratch-win-giveaways-for-website-facebook/trunk/includes/compat/polyfills.php

    r3434870 r3434874  
    33 * Polyfills for PHP 5.4-8.4 compatibility
    44 * Provides backward-compatible functions for PHP 5.4-5.5
    5  * 
     5 *
    66 * @package Scratch & Win
    77 * @since 2.9.3
     
    1515 * hash_equals() polyfill for PHP < 5.6
    1616 * Timing attack safe string comparison
    17  * 
     17 *
    1818 * @link https://www.php.net/manual/en/function.hash-equals.php
    1919 * @param string $known_string The string of known length to compare against
     
    2424    function hash_equals($known_string, $user_string) {
    2525        if (!is_string($known_string)) {
    26             trigger_error('hash_equals(): Expected known_string to be a string', E_USER_WARNING);
    27             return false;
    28         }
    29        
     26            return false;
     27        }
     28
    3029        if (!is_string($user_string)) {
    31             trigger_error('hash_equals(): Expected user_string to be a string', E_USER_WARNING);
    32             return false;
    33         }
    34        
     30            return false;
     31        }
     32
    3533        $known_len = strlen($known_string);
    3634        $user_len = strlen($user_string);
    37        
     35
    3836        if ($known_len !== $user_len) {
    3937            return false;
    4038        }
    41        
     39
    4240        $result = 0;
    4341        for ($i = 0; $i < $known_len; $i++) {
    4442            $result |= ord($known_string[$i]) ^ ord($user_string[$i]);
    4543        }
    46        
     44
    4745        return $result === 0;
    4846    }
     
    5250 * Safe session start wrapper for PHP 5.4-8.4
    5351 * Properly checks session status and headers before starting session
    54  * 
     52 *
    5553 * @return bool True if session started or already active, false otherwise
    5654 */
     
    6159            return false;
    6260        }
    63        
     61
    6462        // For PHP 5.4+ use session_status()
    6563        if (function_exists('session_status')) {
     
    7270            return @session_start();
    7371        }
    74        
     72
    7573        // Fallback for older PHP (pre-5.4, but we support 5.4+)
    7674        if (session_id()) {
    7775            return true;
    7876        }
    79        
     77
    8078        return @session_start();
    8179    }
     
    8583 * Safe JSON decode with error handling
    8684 * Returns default value if JSON is invalid
    87  * 
     85 *
    8886 * @param string $json The JSON string to decode
    8987 * @param bool $assoc Return associative array when true
     
    9694            return $default;
    9795        }
    98        
     96
    9997        $result = json_decode($json, $assoc);
    100        
     98
    10199        if (json_last_error() !== JSON_ERROR_NONE) {
    102100            return $default;
    103101        }
    104        
     102
    105103        return $result !== null ? $result : $default;
    106104    }
     
    110108 * Safe strtolower wrapper for PHP 8.0+ compatibility
    111109 * Handles null values without throwing errors
    112  * 
     110 *
    113111 * @param mixed $string The string to convert to lowercase
    114112 * @return string Lowercase string or empty string if input is invalid
     
    119117            return '';
    120118        }
    121        
     119
    122120        return strtolower((string)$string);
    123121    }
     
    126124/**
    127125 * Check if WC_VERSION constant is defined and optionally compare versions
    128  * 
     126 *
    129127 * @param string $version Version to compare against (optional)
    130128 * @param string $operator Comparison operator (optional)
     
    136134            return false;
    137135        }
    138        
     136
    139137        if ($version === null) {
    140138            return true;
    141139        }
    142        
     140
    143141        return version_compare(WC_VERSION, $version, $operator);
    144142    }
     
    152150 * Safe strlen() wrapper for PHP 8.1+ compatibility
    153151 * PHP 8.1+: Passing null to strlen() is deprecated
    154  * 
     152 *
    155153 * @param mixed $string The string to measure
    156154 * @return int Length of the string, or 0 if invalid
     
    168166 * Safe trim() wrapper for PHP 8.1+ compatibility
    169167 * PHP 8.1+: Passing null to trim() is deprecated
    170  * 
     168 *
    171169 * @param mixed $string The string to trim
    172170 * @param string $characters Characters to trim (optional)
     
    185183 * Safe substr() wrapper for PHP 8.1+ compatibility
    186184 * PHP 8.1+: Passing null to substr() is deprecated
    187  * 
     185 *
    188186 * @param mixed $string The input string
    189187 * @param int $offset Start position
     
    206204 * Safe str_replace() wrapper for PHP 8.1+ compatibility
    207205 * PHP 8.1+: Passing null to str_replace() is deprecated
    208  * 
     206 *
    209207 * @param mixed $search Value to search for
    210208 * @param mixed $replace Value to replace with
     
    235233 * Safe strpos() wrapper for PHP 8.1+ compatibility
    236234 * PHP 8.1+: Passing null to strpos() is deprecated
    237  * 
     235 *
    238236 * @param mixed $haystack The string to search in
    239237 * @param mixed $needle The string to search for
     
    253251 * Safe htmlspecialchars() wrapper for PHP 8.1+ compatibility
    254252 * PHP 8.1+: Passing null to htmlspecialchars() is deprecated
    255  * 
     253 *
    256254 * @param mixed $string The string to convert
    257255 * @param int $flags Flags (optional)
     
    275273 * Safe stripslashes() wrapper for PHP 8.1+ compatibility
    276274 * PHP 8.1+: Passing null to stripslashes() is deprecated
    277  * 
     275 *
    278276 * @param mixed $string The string to process
    279277 * @return string String with backslashes stripped
     
    291289 * Safe explode() wrapper for PHP 8.1+ compatibility
    292290 * PHP 8.1+: Passing null to explode() is deprecated
    293  * 
     291 *
    294292 * @param string $separator The boundary string
    295293 * @param mixed $string The input string
     
    314312 * Also validates array parameter
    315313 * Supports both implode($glue, $array) and implode($array) syntax
    316  * 
     314 *
    317315 * @param string|array $separator The boundary string or array (if single argument)
    318316 * @param mixed $array The array to join (optional)
     
    326324            $separator = '';
    327325        }
    328        
     326
    329327        if (!is_array($array)) {
    330328            return '';
     
    340338 * Safe strtotime() wrapper for PHP 8.1+ compatibility
    341339 * PHP 8.1+: Passing null to strtotime() is deprecated
    342  * 
     340 *
    343341 * @param mixed $datetime The datetime string
    344342 * @param int|null $baseTimestamp Base timestamp (optional)
     
    360358 * Safe preg_match() wrapper for PHP 8.1+ compatibility
    361359 * PHP 8.1+: Passing null to preg_match() is deprecated
    362  * 
     360 *
    363361 * @param string $pattern The pattern to search for
    364362 * @param mixed $subject The input string
     
    386384/**
    387385 * Polyfill for array_key_first() (PHP 7.3+)
    388  * 
     386 *
    389387 * @param array $array Input array
    390388 * @return mixed|null First key or null if array is empty
     
    401399/**
    402400 * Polyfill for array_key_last() (PHP 7.3+)
    403  * 
     401 *
    404402 * @param array $array Input array
    405403 * @return mixed|null Last key or null if array is empty
     
    417415 * Polyfill for str_contains() (PHP 8.0+)
    418416 * Safe version that handles null parameters
    419  * 
     417 *
    420418 * @param mixed $haystack The string to search in
    421419 * @param mixed $needle The string to search for
     
    433431/**
    434432 * Polyfill for str_starts_with() (PHP 8.0+)
    435  * 
     433 *
    436434 * @param mixed $haystack The string to check
    437435 * @param mixed $needle The substring to check for
     
    451449/**
    452450 * Polyfill for str_ends_with() (PHP 8.0+)
    453  * 
     451 *
    454452 * @param mixed $haystack The string to check
    455453 * @param mixed $needle The substring to check for
Note: See TracChangeset for help on using the changeset viewer.