PccfToPcfOverride

Summary: Allows existing recipes to run on PHP 7 without causing deprecated create_function() messages.
Version: 2018-07-07
Prerequisites: PmWiki version 2.2.108 (but see Usage below).
Status: Beta
Maintainer: Chuck G
License: GPL
Users: (view? / edit)

Questions answered by this recipe

How can I upgrade my server to PHP 7.2 without getting "create_function() is deprecated" warnings?

Description

The pccf2pcf.phpΔ script circumvents the use of PHP's create_function() by calls to PCCF, PPRE and Markup_e. It can also display a summary of these calls to the Stopwatch.

Installation

Download and install pccf2pcf.phpΔ to your cookbook directory.

To your config.php file, add:

    $EnablePCF     = 1; # Circumvent calls to create_function()
                        #   by PCCF, PPRE and Markup_e

and / or:

    $EnablePCFWarn = 1; # Display a summary of the calls
                        #   to PCCF, PPRE and Markup_e
    $PCFRootPat    = '%^.*?/your-document-root/(.*)%';
                    # Causes PCFWarn to drop the path thru your-document-root
                    #   to shorten displayed file names

Also add:

    include_once ("$FarmD/cookbook/pccf2pcf.php");

Usage

You can enable one or both of PCF and PCFWarn:

  • Enabling PCF circumvents calls by PCCF, PPRE and Markup_e to PHP's create_function(), thus eliminating "deprecated create_function()" messages and allowing recipes to work in future PHP versions.
  • Enabling PCFWarn causes a summary of calls to PCCF, PPRE and Markup_e to be added to the StopWatch, which appears at the bottom of pages. It enables display of the StopWatch, so it is not necessary to follow the directions under "Enabling the stopwatch" in Cookbook.Stopwatch.

This recipe uses the $PCCFOverrideFunction feature, which is new in PmWiki 2.2.108. However, it can be used in older PmWiki versions by patching pmwiki.php. This is not recommended, but if you must, here is the change.

In pmwiki.php, after the code:

  function PCCF($code, $template = 'default', $args = '$m') {
    global $CallbackFnTemplates, $CallbackFunctions;
Insert:
    global $PCCFOverrideFunction;
    if ($PCCFOverrideFunction && is_callable($PCCFOverrideFunction))
      return $PCCFOverrideFunction($code, $template, $args);

Notes

This script uses PHP's eval() function to emulate create_function().

  • eval() is considered unsafe, but probably no more so than create_function(), which uses eval() internally.
  • eval() may be deprecated some time in the future.

For these reasons, this should be considered a temporary solution. Note, however, that enabling PCFWarn but not PCF will display diagnostic information while continuing to use create_function() instead of eval(). This would be useful for determining future problems before upgrading to PHP 7.

Change log / Release notes

2018-07-07
Initial release.

Comments

See discussion at PccfToPcfOverride-Talk?

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.