• Resolved dashed-slug.net

    (@dashedslug)


    Hello,

    I am using version 2.4.0 of this plugin on a WordPress that runs on PHP 8.2.12.

    I have been running some PHP code on the console that has Namespace declarations. I noticed that there is always a stack trace dumped in the logs.

    I did a little investigating and fixed the problem for me, but I’d like to report the issue to you too:

    First, the error:

    PHP Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/wordpress/wp-content/plugins/wp-console/vendor/psy/psysh/src/CodeCleaner/UseStatementPass.php on line 53

    I looked into the UseStatementPass class. It seems like the private field $lastNamespace is initialized to null. So when the node parser finds the name of the Namespace node, it compares it with strtolower( $this->lastNamespace ) and this is no longer OK in PHP 8. I think this is why the error is shown.

    If I change the private field $lastNamespace to be initialized to an empty string, the error goes away. It sure helps me, because I am constantly monitoring my logs for bugs in my code, and the stack trace was confusing me.

    It’s obviously a bug in psysh, but it’s been fixed in the latest version that they have on github:

    https://github.com/bobthecow/psysh/blob/7e0785b74410d6ed4b07e4398c5e1137a402e09f/src/CodeCleaner/UseStatementPass.php#L56C1-L56C1

    They have changed the line:

            if (\strtolower($node->name) === \strtolower($this->lastNamespace)) {

    to:

            if (\strtolower($node->name ?: '') === \strtolower($this->lastNamespace ?: '')) {

    If you’re planning to do another release for this plugin, perhaps you can do a composer update to fix this for everyone else?

    Thanks again for the great plugin, I use it all the time.

    with regards,

    Alex

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Edi Amin

    (@ediamin)

    Hi @dashedslug, thank you for reporting the bug. Could you please share your code that causes this issue? I have found the code that causes the error as you suggested, but I need to reproduce the error for verification purpose.

    Thread Starter dashed-slug.net

    (@dashedslug)

    Hello @ediamin,

    Example code that causes the issue:

    namespace DSWallets;
    1;

    Example code that does not cause the issue:

    1;

    This should be enough to reproduce.

    I don’t think you need to fix your own code, just updating the third party component will resolve the issue in psysh.

    Thanks!

    Alex

    Plugin Author Edi Amin

    (@ediamin)

    @dashedslug WP Console is compatible with PHP versions ranging from 5.6 to 8.2. This is the reason I can’t immediately upgrade the psysh version. I am currently using separate compat files to ensure support for PHP 8.0 and higher.

    I have updated the plugin to version 2.4.1. Please download the latest version and let me know if it resolves the problem. Thank you.

    Thread Starter dashed-slug.net

    (@dashedslug)

    @ediamin, the issue is resolved in 2.4.1.

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Stacktrace dumped in logs when parsing Namespace statements’ is closed to new replies.