[pmwiki-users] Recipes you use/need to be updated for PHP 5.5

Petko Yotov 5ko at 5ko.fr
Sat Jan 4 14:17:30 CST 2014

John Rankin writes:
> > If you maintain recipes on the cookbook and wish to update your recipe,
> > see
> >   http://www.pmwiki.org/wiki/PmWiki/CustomMarkup#php55
> What does one do with lines like the following?
>         $FmtP['/\\$LastModified/e'] = '$GLOBALS[\'CurrentTime\']';
> I assume the /e will cause a problem.

This will still work on PmWiki running on PHP 5.4 or earlier.

In order to work with PHP 5.5 without triggering a warning, use one of  

  # complex replacements:
  $FmtP['/\\$LastModified/'] = PCCF('return $GLOBALS["CurrentTime"];');
  # -OR-
  $FmtP['/\\$LastModified/'] = 'myfunc';
  function myfunc($matches) { your code; return $out;}

  # this particular simple replacement:
  SDV($CurrentTime, strftime($TimeFmt, $Now)); # define it if undefined
  $FmtP['/\\$LastModified/'] = $CurrentTime; # -OR-
  $FmtP['/\\$LastModified/'] = $GLOBALS["CurrentTime"];

(this requires at least pmwiki-2.2.56)

Note that for $FmtP and other replacement patterns like $ROSPatterns some  
variables previously available in the scope of the calling function may  
become out of scope in the replacement patterns and not exist. For example,  
if in your replacement parts you have some $variable not global ($fmt,  

I'm not sure yet how to deal with that - an admin reported this with the  
$fmt variable for $FmtP patterns, and I fixed it, but there may be more. In  
any case, if a related bug is reported to me, I'll provide a solution ASAP.

> I also have a lot of code that needs to be changed to use
> preg_replace_callback instead of preg_replace with /e. Sigh.

You can read the helper PCCF() ie. "PmWiki Create Callback Function" in  
pmwiki.php, which may help you migrate. It was also added in 2.2.56.


More information about the pmwiki-users mailing list