{"id":17185383,"date":"2023-11-08T17:16:05","date_gmt":"2023-11-08T17:16:05","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/stacktrace-dumped-in-logs-when-parsing-namespace-statements\/"},"modified":"2023-11-08T17:16:05","modified_gmt":"2023-11-08T17:16:05","slug":"stacktrace-dumped-in-logs-when-parsing-namespace-statements","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/stacktrace-dumped-in-logs-when-parsing-namespace-statements\/","title":{"rendered":"Stacktrace dumped in logs when parsing Namespace statements"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hello,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I am using version <code>2.4.0<\/code> of this plugin on a WordPress that runs on PHP <code>8.2.12<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I did a little investigating and fixed the problem for me, but I&#8217;d like to report the issue to you too:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, the error:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>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<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">I looked into the <code>UseStatementPass<\/code> class. It seems like the private field <code>$lastNamespace<\/code> is initialized to <code>null<\/code>. So when the node parser finds the name of the Namespace node, it compares it with <code>strtolower( $this-&gt;lastNamespace )<\/code> and this is no longer OK in PHP 8. I think this is why the error is shown.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If I change the private field <code>$lastNamespace<\/code> 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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It&#8217;s obviously a bug in psysh, but it&#8217;s been fixed in the latest version that they have on github:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">https:\/\/github.com\/bobthecow\/psysh\/blob\/7e0785b74410d6ed4b07e4398c5e1137a402e09f\/src\/CodeCleaner\/UseStatementPass.php#L56C1-L56C1<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">They have changed the line:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        if (\\strtolower($node-&gt;name) === \\strtolower($this-&gt;lastNamespace)) {<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        if (\\strtolower($node-&gt;name ?: '') === \\strtolower($this-&gt;lastNamespace ?: '')) {<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you&#8217;re planning to do another release for this plugin, perhaps you can do a composer update to fix this for everyone else?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks again for the great plugin, I use it all the time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">with regards,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Alex<\/p>\n","protected":false},"template":"","class_list":["post-17185383","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/17185383","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/17185383\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=17185383"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}