On 05/02/2018 11:36, Moni Kellermann wrote:
Am 02.02.2018 um 18:51 schrieb Petko Yotov:
Hello. PmWiki version 2.2.107 was published today

I am trying out this skin:
http://www.pmwiki.org/wiki/Skins/Vanilla5

With PmWiki 2.2.107 running on XAMPP/PHP 7.21, I now get the error

Deprecated: Function create_function() is deprecated in
C:\xampp\htdocs\pmwiki-2.2.107\pmwiki.php on line 481

which refers to the section

function PCCF($code, $template = 'default', $args = '$m') {
...

and specifically the line

  $fn = create_function($args, $code);

I understand that create_function is deprecated in PHP 7.2, and that
the fault is with the skin, not with PmWiki, as the standard skins do
not trigger this.

Which means that a) we need to fix both pmwiki.php as well as the skin.
I get the same error with the Twitter Bootstrap skin.

Both those skins work with 2.2.107 when running XAMPP/PHP 5.6.33.

The line will not trigger a warning in PHP 7.2 if no recipe or skin calls PCCF() directly or via other functions, notably Markup_e(). PmWiki doesn't call this function any more and there are about 159 recipes and 71 skins that are reported PHP 7.2 compatible - I've reviewed most of these and rewrote some of those that needed updates.

The line in itself doesn't need fixing, and it works fine on older PHP versions (and on PHP 7.2 as long as it is not called). An administrator can even configure the server not to show "Deprecated" warnings if they like, and the function will work fine.

I have rewritten the documentation about the PHP changes and the way to update recipes:
  http://www.pmwiki.org/wiki/PmWiki/Troubleshooting
  http://www.pmwiki.org/wiki/PmWiki/CustomMarkup

I can provide assistance to maintainers of recipes and skins if the instructions are insufficient or if there is another problem, but when there are active maintainers listed on a recipe or skin page, I prefer to let them update their work. They should not hesitate to contact me if they encounter any difficulty or if they have any question. :-)

For example, the Vanilla5/skin.php file can be updated this way:

Instead of these 2 lines:
Markup_e('nosearch', 'directives', '/\\(:nosearch:\\)/i', "SetTmplDisplay('PageSearchFmt',0)"); Markup_e('notabs', 'directives', '/\\(:notabs:\\)/i', "SetTmplDisplay('PageTabsFmt',0)");

We add these:
Markup('nosearch', 'directives', '/\\(:nosearch:\\)/i', "v5_nosearch");
  Markup('notabs', 'directives',  '/\\(:notabs:\\)/i', "v5_notabs");

  function v5_nosearch() {
    SetTmplDisplay('PageSearchFmt',0);
  }

  function v5_notabs() {
    SetTmplDisplay('PageTabsFmt',0);
  }

Instead of the evaluated code passed as 4-th argument to Markup_e(), we pass a function name to Markup().

The above will work in PHP 7.2 without errors but also in any PHP 5+ (probably 4+) versions on PmWiki 2.2.56 or newer. The above can be written in a number of different and correct ways, for example like the function MarkupTmplDisplay() in scripts/stdmarkup.php. A developer can select the way s/he likes most.

It is also possible to pass a lambda function or closure as a 4-th argument, for example:

  Markup('notabs', 'directives',  '/\\(:notabs:\\)/i',
    function(){ SetTmplDisplay('PageTabsFmt',0); } );

While I find this elegant, it will only work in PHP 5.3 or newer so the PmWiki core and my own addons do not use this method. If a recipe maintainer chooses this method instead of passing a function name, the recipe page should note the PHP 5.3 prerequisite.

Petko

_______________________________________________
pmwiki-users mailing list
[email protected]
http://www.pmichaud.com/mailman/listinfo/pmwiki-users

Reply via email to