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
Assigned:
Priority: 5
Version: newest
OS: ubuntu linux 14/apache/php 5.6

Description:

http://www.pmwiki.org/wiki/Cookbook/EZDate

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:

  EZDate($m) { # CHANGE ARGUMENT
    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

Array
(
    [post_max_size] => 64M
    [$_POST keys] => 
    [$_REQUEST keys] => n
    [$_SERVER] => Array
        (
            [CONTEXT_DOCUMENT_ROOT] => /home/pmwiki/public_html
            [CONTEXT_PREFIX] => 
            [DOCUMENT_ROOT] => /home/pmwiki/public_html
            [GATEWAY_INTERFACE] => CGI/1.1
            [HTTPS] => on
            [HTTP_ACCEPT] => */*
            [HTTP_ACCEPT_ENCODING] => gzip, br, zstd, deflate
            [HTTP_HOST] => www.pmwiki.org
            [HTTP_REFERER] => http://www.pmwiki.org/wiki/PITS/01419
            [HTTP_USER_AGENT] => Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
            [HTTP_X_HTTPS] => 1
            [PATH] => /bin:/usr/bin
            [PHP_INI_SCAN_DIR] => /opt/cpanel/ea-php70/root/etc:/opt/cpanel/ea-php70/root/etc/php.d:.
            [QUERY_STRING] => n=PITS%2f01419
            [REDIRECT_HTTPS] => on
            [REDIRECT_QUERY_STRING] => n=PITS%2f01419
            [REDIRECT_SCRIPT_URI] => https://www.pmwiki.org/wiki/PITS/01419
            [REDIRECT_SCRIPT_URL] => /wiki/PITS/01419
            [REDIRECT_SSL_TLS_SNI] => www.pmwiki.org
            [REDIRECT_STATUS] => 200
            [REDIRECT_UNIQUE_ID] => afKMhZALw2rT9WobaMcsCgAAAQA
            [REDIRECT_URL] => /wiki/PITS/01419
            [REMOTE_ADDR] => 216.73.216.31
            [REMOTE_PORT] => 5933
            [REQUEST_METHOD] => GET
            [REQUEST_SCHEME] => https
            [REQUEST_URI] => /wiki/PITS/01419
            [SCRIPT_FILENAME] => /home/pmwiki/public_html/index.php
            [SCRIPT_NAME] => /index.php
            [SCRIPT_URI] => https://www.pmwiki.org/wiki/PITS/01419
            [SCRIPT_URL] => /wiki/PITS/01419
            [SERVER_ADDR] => 23.254.203.248
            [SERVER_ADMIN] => webmaster@pmwiki.org
            [SERVER_NAME] => www.pmwiki.org
            [SERVER_PORT] => 443
            [SERVER_PROTOCOL] => HTTP/1.1
            [SERVER_SIGNATURE] => 
            [SERVER_SOFTWARE] => Apache
            [SSL_TLS_SNI] => www.pmwiki.org
            [TZ] => America/Los_Angeles
            [UNIQUE_ID] => afKMhZALw2rT9WobaMcsCgAAAQA
            [PHP_SELF] => /index.php
            [REQUEST_TIME_FLOAT] => 1777503365.3505
            [REQUEST_TIME] => 1777503365
            [argv] => Array
                (
                    [0] => n=PITS%2f01419
                )

            [argc] => 1
        )

)