01419: ezdate recipe no longer works on php 5.6

Summary: ezdate recipe no longer works on php 5.6
Created: 2017-09-01 10:01
Status: Closed, replied
Category: Cookbook
From: gnuzoo
Priority: 5
Version: newest
OS: ubuntu linux 14/apache/php 5.6



It uses the 'e' on preg_replace. If you can fix this one recipe I will use it as an example and fix the rest of my recipes that use 'e'.

gnuzoo September 01, 2017, at 10:01 AM

Try with this code:

  Markup('EZDate', 'fulltext', '/\\(:(ezdate|eztime)(\\s.*?)?:\\)/i', "EZDate");

Then change the EZDate function to:

    list($no, $name, $args) = $m; # ADD LINE

See PmWiki:CustomMarkup for more information. --Petko September 01, 2017, at 10:21 AM

What is the 1st variable in the list function call '$no' ???

This is $m[0] which needs to be dropped/discarded. Currently you can write list( , $name, $args) but future PHP versions will apparently disallow this, so I use a temporary unused variable. --Petko September 01, 2017, at 11:11 AM

Thanks for the explanation.

Please may I suggest that instead of '$no' you use '$ignore_this_variable' or something like that.

I am curious why we drop the 1st element of the array $m.

We don't drop the first element, we assign it. We drop the zeroth element, because you didn't have "$0" in your replacement evaluation. --Petko September 01, 2017, at 11:29 AM

Arrays in PHP are base zero, therefore $m[0] is the "first" element.

There are 3 backreferences, $1 & $2 are nested inside $0.

Thanks for the explanation - that makes sense now . Its been about 10 year since I looked at this.

Here is the new code: http://www.pmwiki.org/pmwiki/uploads/Cookbook/EZDate.php

Do I need to make it backward compatible? I mean if someone still using PHP < 5.6 ?

It will work on older PHP versions too, but requires PmWiki 2.2.56 or newer. --Petko