01488: PHP 8.1 logs deprecation and warning...

Summary: PHP 8.1 logs deprecation and warning...
Created: 2023-03-17 10:43
Status: Closed, fixed for 2.3.22
Category: PHP Compatibility
From: JohnnyN
Assigned:
Priority: 1
Version: 2.3.21
OS: Linux/Apache/PHP-8.1

Description: When PmWiki 2.3.21 redirects, this gets logged in the PHP 8.1 log:

PHP Deprecated:  preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /path/to/public_html/pmwiki.php on line 1970
PHP Warning:  Undefined variable $anchor in /path/to/public_html/pmwiki.php on line 1975

Patch, compatible with PHP 5.3, according to the PHP5 manual:

--- pmwiki-2.3.21.php	2023-02-13 08:36:27.000000000 +0100
+++ pmwiki-2.3.21-patched.php	2023-03-17 11:16:24.002218245 +0100
@@ -1967,12 +1967,12 @@
   if (@$opt['from'] 
       && !MatchPageNames($pagename, FixGlob($opt['from'], '$1*.$2')))
     return '';
-  if (preg_match('/^30[1237]$/', @$opt['status'])) 
+  if (isset($opt['status']) && preg_match('/^30[1237]$/', $opt['status'])) 
      header("HTTP/1.1 {$opt['status']}");
   Redirect($to, "{\$PageUrl}"
     . (IsEnabled($EnableRedirectQuiet, 0) && IsEnabled($opt['quiet'], 0)
       ? '' : "?from=$pagename")
-    . $anchor);
+    . (isset($anchor) ? $anchor : ''));
   exit();
 }

Best regards :o)

Johnny :o)

JohnnyN

Thanks, fixed with strval(@$opt['status']) as we usually do. --Petko