• Resolved Kevin Shenk

    (@batonac)


    My debug log is filled with deprecated notices when running this plugin on PHP 8.1:

    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155
    [25-Jul-2023 14:49:01 UTC] PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-content/plugins/woo-photo-reviews/includes/mobile_detect.php on line 1155

    I patched the function in question as follows:

    		/**
    		 * Some detection rules are relative (not standard),
    		 * because of the diversity of devices, vendors and
    		 * their conventions in representing the User-Agent or
    		 * the HTTP headers.
    		 *
    		 * This method will be used to check custom regexes against
    		 * the User-Agent string.
    		 *
    		 * @param string $regex
    		 * @param string|null $userAgent
    		 *
    		 * @return bool
    		 *
    		 * @todo: search in the HTTP headers too.
    		 */
    		public function match($regex, $userAgent = null) {
    			// Ensure that $userAgent is a non-null string.
    			$userAgent = is_string($userAgent) ? $userAgent : '';
    
    			$match = (bool) preg_match(sprintf('#%s#is', $regex), $userAgent, $matches);
    
    			// If positive match is found, store the results for debug.
    			if ($match) {
    				$this->matchingRegex = $regex;
    				$this->matchesArray  = $matches;
    			}
    
    			return $match;
    		}

    But the question still remains… why is this function being called on every single page load, even those that are not displaying or collecting photo reviews? That’s a real waste of CPU cycles.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Deprecation Notices & Wasted CPU’ is closed to new replies.