Stacktrace dumped in logs when parsing Namespace statements
-
Hello,
I am using version
2.4.0
of this plugin on a WordPress that runs on PHP8.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 tonull
. So when the node parser finds the name of the Namespace node, it compares it withstrtolower( $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:
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
- The topic ‘Stacktrace dumped in logs when parsing Namespace statements’ is closed to new replies.