• Resolved Matt

    (@silvercolt45)


    I hope someone can assist me with identifying why WordPress rejects the “|” (pipes) used as bitwise OR statements for the variable types.

    if (!function_exists('mb_convert_encoding')) {
        function mb_convert_encoding(array|string $string, string $to_encoding, array|string|null $from_encoding = null): array|string|false { return p\Mbstring::mb_convert_encoding($string, $to_encoding, $from_encoding); }
    }

    I am running in PHP 7.3 and have pulled in the Twig/Symfony composer libraries (v3.1.1) which requires PHP >=7.2.5.

    Every time I try and commit the Twig/Symfony libraries to my plugin’s SVN repository, it results in the following:

    svn: E165001: Commit failed (details follow):
    svn: E165001: Commit blocked by pre-commit hook (exit code 1) with output:
    ***********************************
    PHP error in: starfish-reviews/tags/2.3.28/composer/vendor/symfony/polyfill-mbstring/bootstrap80.php:
    Parse error: syntax error, unexpected '|', expecting variable (T_VARIABLE) in Standard input code on line 15
    Errors parsing Standard input code
    ***********************************
Viewing 5 replies - 1 through 5 (of 5 total)
  • I think the linter was only updated to 7.1 a couple of months ago.
    I don’t think there’s a schedule for updating it.

    Thread Starter Matt

    (@silvercolt45)

    The WordPress Plugins team responded with this. Thank you Team!

    That line, and indeed that file, requires PHP 8.0 to work.

    Now, when you’re running the code normally, in PHP 7.3, then that whole file doesn’t get included. If you look in the bootstrap.php file, you’ll find this code:

    if (\PHP_VERSION_ID >= 80000) {
    return require __DIR__.’/bootstrap80.php’;
    }

    That means that it only loads that file in PHP 8 and up.

    Our linter runs on PHP 7.4, which is what the site itself runs on. But it’s linting each file, it doesn’t actually run your code. So that file can’t pass the lint check, because it’s PHP 8 specific code.

    The solution for now is simply to downgrade the version of the library you’re using. I’m not familiar enough with composer to tell you the proper way to do that, but essentially you need to be using the 7.4 compatible version of the symphony-polyfill library.

    When www.ads-software.com itself is using PHP 8, then the linter will lint to that, and then PHP 8-only code will be allowed into the directory There is no timeline on that, but it’s likely to happen sometime this year.

    Why is WP such a tremendously shit platform to develop…

    Thanks for sharing this “insight” from the WP team.

    Hi guys.

    Instead of downgrading you could just remove type annotations as part as your workflow via a sed command.

    I have a file with replacements and I do this:

    
    find . -type f -name bootstrap80.php -exec sed -i .bak -f bootstrap80.php.sed {} +
    find . -name "*.bak" -exec rm {} +
    

    The sed file looks like:

    
    s/: bool//g
    s/: string\|false//g
    
    • This reply was modified 3 years, 5 months ago by Doofinder.

    For anyone else running into this, the latest unproblematic version of the package is 1.20.0. You can fix it in the composer.json:

    {
        "require": {
            "symfony/polyfill-mbstring": "1.20.0",
        },
    }
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Errors parsing Standard input code: Bitwise OR ‘|’’ is closed to new replies.