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?


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.


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");

You need to add the above before any call to PCCF() which could happen in config.php or in an included file, so best is to add it near the top of farmconfig.php or config.php.


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;
    global $PCCFOverrideFunction;
    if ($PCCFOverrideFunction && is_callable($PCCFOverrideFunction))
      return $PCCFOverrideFunction($code, $template, $args);


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

Initial release.


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.