01461: PHP 8

Summary: PHP 8
Created: 2020-12-01 06:14
Status: InProgress
Category: PHP Compatibility
Assigned:
Priority: 4
Version: 2.2.135
OS:

Description: PHP 8 has made a number of breaking changes, so code that previously worked fine now needs to be rewritten.

On this page we keep track of the work done and pending to update the core codebase for PHP 8.

Note: reports should be made for the nightly snapshot. If you use an older version, please upgrade first.

Pending issues

Please add new reports below this line.


When working with PHP 7.4 my installation is now completely without warnings, even on page editing with the recipe editattr.php (in conjunction with pccf2pcf.php) and on problematic pages with a lot of scripting. When moving to PHP 8.0 the following warnings occur (all on core scripts):

  1. [28-Mar-2022 19:55:10 Europe/Berlin] PHP Warning: Undefined array key "postdraft" in .../scripts/draft.php on line 59
  2. [28-Mar-2022 19:55:10 Europe/Berlin] PHP Warning: Undefined array key "postedit" in .../scripts/draft.php on line 59
  3. [28-Mar-2022 19:55:10 Europe/Berlin] PHP Warning: Undefined array key 0 in .../scripts/markupexpr.php(111) : eval()'d code on line 1
  4. [28-Mar-2022 19:55:10 Europe/Berlin] PHP Warning: Undefined array key "text" in .../scripts/notify.php on line 104
  5. [28-Mar-2022 19:55:10 Europe/Berlin] PHP Warning: Undefined array key 0 in .../scripts/markupexpr.php(111) : eval()'d code on line 1

This is just to inform you for future releases. It is OK for me to work further with PHP 7.4. Siegfried Seibert

Drafts and Notify were fixed. It would again be useful to know the markup expression that causes the warning. --Petko


Should be fixed

When Upgrading to PHP 8 (with PmWiki 2.3.2) I got a lot of PHP-Warnings "Undefined array key". I fixed this in my own config.php with $FmtPV['$urlgroup'] = chkget($_GET['group'] ?? ''); (from: https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-warning-undefined-arr#4261200). Hope that this is right. There are still some messages from pmwiki core scripts:

[26-Mar-2022 02:23:57 Europe/Berlin] PHP Warning: Undefined array key 0 in .../scripts/markupexpr.php(111) : eval()'d code on line 1
[26-Mar-2022 02:23:57 Europe/Berlin] PHP Warning: Undefined array key "=protectsafe" in .../scripts/pagelist.php on line 610
[26-Mar-2022 02:23:57 Europe/Berlin] PHP Warning: Undefined array key "=protectsafe" in .../scripts/pagelist.php on line 610
[26-Mar-2022 02:23:57 Europe/Berlin] PHP Warning: Undefined array key "text" in .../scripts/notify.php on line 104
[26-Mar-2022 02:23:57 Europe/Berlin] PHP Warning: Undefined array key "squelch" in .../scripts/notify.php on line 137
[26-Mar-2022 02:23:57 Europe/Berlin] PHP Warning: Undefined array key "squelch" in .../notify.php on line 137
[26-Mar-2022 02:23:57 Europe/Berlin] PHP Warning: Undefined array key "squelch" in .../scripts/notify.php on line 137
[26-Mar-2022 03:08:18 Europe/Berlin] PHP Warning: Undefined array key "rev" in .../pmwiki.php(1178) : eval()'d code on line 1

Siegfried Seibert at 2022 March 26, 02:57 MEZ

Thank you for the report, very much appreciated. For the markup expression, it may be useful to tell me what expression is being evaluated in the page. "Notify" has been reported and should have been fixed in the pre-release. The others were fixed today, nevertheless I didn't see the same warnings before so in case something is not right, please let me know. A new version 2.3.3 will be released shortly. --Petko

Thanks. I just installed the new PmWiki 2.3.3. After a quick test it seems that all the warnings are gone, except Undefined array key "=protectsafe" in .../scripts/pagelist.php . Now on line 611. Siegfried Seibert

It seems that there ist still a warning from notify.php: PHP Warning: Undefined array key "text" in .../scripts/notify.php on line 104 Siegfried Seibert

Unfortunately I still cannot experience this -- I suspect your configuration has some differences from mine. I made another change that should silence it, you can get the partial export from PmWiki:ChangeLog (only pagelist.php changed) and please report if it was fixed. --Petko

Thank You, I tried the modified pagelist.php and the warning disappeared on the pages where they formerly occurred. But when I understand your message right, this only silenced the warning but did not solve the problem itself, which may come from my configuration. So I still have to check my configuration? I still have some other warnings concerning Custom Markup Expressions, which I will have to check during the next few days too. Once again thank you very much. Siegfried Seibert

The change I made makes it behave like before PHP 8, that is, an undefined variable will be cast to an empty array, so I would not worry about it anymore. Actually I believed the other change I made in that function would already do this, but apparently in some cases it didn't. For custom markup expressions, or for other variables or array elements that raise warnings, my current solution is to explicitly cast them to the expected types with intval(@$var), floatval(@$var), strval(@$var), or (array)@$var. PmWiki was designed to work this way, forgiving things that are not completely defined, and assuming 0, array(), or "" (empty string). The Null coalesce operator ?? is great but requires PHP 7, and we still want to keep PmWiki PHP 5.5 compatible.

We should probably write some helper functions to help with this, but it looks daunting. The main difficulty to make the same code work for old and new PHP versions is that the "undefined" thing may be a variable (of several types), an array or it can be a missing key to an existing array, and all these would be treated differently in PHP 5. For the moment it seems to me easier/clearer to just use intval/strval/etc. --Petko


Closed issues

Click to toggle past issues

Custom MarkupExpressions

Concerning the markup expressions I got the following fatal error on a page using the Custom Markup Expression add1 (from MarkupExpressionSamples):

[26-Mar-2022 10:50:06 Europe/Berlin] PHP Fatal error: Uncaught TypeError: Unsupported operand types: string + int in .../scripts/markupexpr.php(111) : eval()'d code:1
Stack trace:

  1. .../scripts/markupexpr.php(111): eval()
  2. .../scripts/markupexpr.php(62): MarkupExpression('Site.LocalTempl...', '(add1 {$$PageCo...')
  3. [internal function]: MarkupMarkupExpression(Array)
  4. .../pmwiki.php(2156): preg_replace_callback('/\\{(\\(\\w+\\b.*?\\...', 'MarkupMarkupExp...', '(:if1 false:)\n[...')
  5. .../scripts/stdmarkup.php(592): MarkupToHTML('Site.LocalTempl...', '(:if1 false:)\n[...', Array)
  6. .../scripts/stdmarkup.php(610): MarkupMarkup('Site.LocalTempl...', '(:if1 false:)\n[...', Array)
  7. [internal function]: MarkupMarkupMarkup(Array)
  8. .../pmwiki.php(2156): preg_replace_callback('/\\(:(markup)(\\s...', 'MarkupMarkupMar...', '(:groupheader:)...')
  9. .../pmwiki.php(2454): MarkupToHTML('Site.LocalTempl...', '(:groupheader:)...')
  10. .../pmwiki.php(2237): PreviewPage('Site.LocalTempl...', Array, Array)
  11. .../pmwiki.php(2501): UpdatePage('Site.LocalTempl...', Array, Array)
  12. .../pmwiki.php(438): HandleEdit('Site.LocalTempl...', 'edit')
  13. .../pmwiki.php(425): HandleDispatch('Site.LocalTempl...', 'edit')
  14. {main}
  15. thrown in .../scripts/markupexpr.php(111) : eval()'d code on line 1

I will try to change $MarkupExpr['add1'] = '$args[0]+1'; to SDVA($MarkupExpr, array('add1' => '$args[0]+1')); similar to the handling in scripts/markupexpr.php. Siegfried Seibert

SDV will not help. See how you can change it: diff. --Petko

Thank You, Petko. That worked. Siegfried Seibert


On my wiki with AuthUser enabled, I get the following warnings after login (subsequent pages load without displaying the warnings):

  • Warning: Undefined variable $authlist in /usr/local/var/www/Default/public_html/pmwiki/scripts/authuser.php on line 76
  • Warning: Undefined array key "htgroup" in /usr/local/var/www/Default/public_html/pmwiki/scripts/authuser.php on line 89

I was able to fix these by adding $authlist to function AuthUserId()'s globals declaration and adding a null coalescing operator to line 89:

  if ($auth['htgroup'] ??= NULL) {

Thanks for your report. Just 2 notes: $authuser is not intended to be global but passed by reference, and the core needs to work with PHP 5. For these reasons, see my fix below. --Petko May 05, 2021, at 04:57 PM

Index: scripts/authuser.php
===================================================================
--- scripts/authuser.php	(revision 3719)
+++ scripts/authuser.php	(working copy)
@@ -70,6 +70,7 @@
     }
   }

+  $authlist = array();
   if (func_num_args()==2) $authid = $id;
   else
     foreach($AuthUserFunctions as $k => $fn) 
@@ -86,7 +87,7 @@
     $authlist[$g] = 1;
   foreach(preg_grep('/^@/', array_keys($auth)) as $g) # useless? PITS:01201
     if (in_array($authid, $auth[$g])) $authlist[$g] = 1;
-  if ($auth['htgroup']) {
+  if (@$auth['htgroup']) {
     foreach(AuthUserHtGroup($pagename, $id, $pw, $auth['htgroup']) as $g)
       $authlist["@$g"] = 1;
   }

If $LinkWikiWords = 1; is set I get warnings like the following on pages which contains CamelCase words:

  Warning: Undefined array key "EximCfgMain" in /home/www/pmwiki/scripts/wikiwords.php on line 66

Thanks, this was fixed for the next version (due in a few days). --Petko April 13, 2021, at 03:25 PM


Under php 8.0 pmwiki enters in infinite loop. It's because of change of comparing rules in php 8.0.

In pmwiki.php (line 1580) instead of

  if ($depth == 0) $depth = strlen($depth);
  if ($icol == 0) $icol = strlen($icol);

must be

  if (!is_numeric($depth)) $depth = strlen($depth);
  if (!is_numeric($icol)) $icol = strlen($icol);

Yury Finkel? December 01, 2020, at 06:14 AM


Made this change manually on my system as php 8 just dropped on Arch linux. pmwiki works with these changes...

...thanks Yury.

...Roy H


well - the pages render and load (which they didn't before) - but editing still doesn't work. Uncaught TypeError: Unsupported operand types int & arry line 2182 of pmwiki.php. Probably several more things to fix for the new version of PHP.

...Roy

I'll publish the next version that fixes these and a few other compatibilities (Forms) in the next few days, this week or early next week. --Petko January 28, 2021, at 08:30 PM

What a blessing to have you.

MFWolff January 29, 2021, at 07:08 AM

All the above, and a few I found myself, were fixed. If there are any others, please report them in the "Pending issues" section. --Petko January 31, 2021, at 05:19 PM