• Moving from PHP 7.4 to PHP 8.1 trigger this warning message

    ( ! ) Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in \wp-content\plugins\wp-syntax\wp-syntax.php on line 383

    Solution:
    Remove the ampersand before $match at the line 241

    New 241 line:
    public static function substituteToken( $match ) {

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter menestrala

    (@menestrala)

    No way. Further warnings and errors make it completely unusable.

    Webrocker

    (@webrocker)

    Had the same Warning.

    Instead of just removing the ampersand as noted above, I made the reference inside that function:

    public static function substituteToken( $match ) {
     // global $wp_syntax_token, $wp_syntax_matches;
     // &$match was in the function param before:
     $m = &$match;
     $i = count( self::$matches );
     self::$matches[ $i ] = $m;
     return "\n\n<p>" . self::$token . sprintf( '%03d', $i ) . "</p>\n\n";
    }
    

    plus I had to change “create_function()” in geshi/geshi.php l 4750ff to a regular funcion:

    if (!isset($callback_2)) {
     // throws error in php8:
     //$callback_2 = create_function('$matches', 'return "[" . str_replace("|", "", $matches[1]) . "]";');
     // works:
     $callback_2 = function($matches){
     return "[" . str_replace("|", "", $matches[1]) . "]";
     };
    }
    

    (https://www.php.net/manual/en/function.create-function.php) is no more in PHP8

    this seems to have fixed the warning/errors for me.

    • This reply was modified 2 years ago by Webrocker.
    • This reply was modified 2 years ago by Webrocker. Reason: code formatting and comments
    • This reply was modified 2 years ago by Webrocker.

    I downloaded the latest GeSHi code and replaced the /geshi/ folder in the plugin:
    /geshi-1.0-master/src/ -> /wp-content/plugins/wp-syntax/geshi/

    https://github.com/GeSHi/geshi-1.0

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Warning message moving from PHP 7.4 to PHP 8.1’ is closed to new replies.