WordPress/WordPress-Coding-Standards

PrefixAllGlobalsSniff - Passing null to parameter #1 ($string) of type string is deprecated

tomdevisser opened this issue · 16 comments

Bug Description

After downloading a fresh copy of WPCS I get the following error:

An error occurred during processing; checking has been aborted. The error message was: trim(): Passing null to parameter #2087 /Users/{username}/Developer/wpcs/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php on line 280

Minimal Code Snippet

The issue happens when running this command:

phpcs index.php

... over a file containing this code:

<?php

echo 'Hello WordPress';

Custom ruleset

I'm using the WordPress-Extra standard.

Environment

Question Answer
PHP version 8.2.1
PHP_CodeSniffer version 3.7.1
WPCS version latest
WPCS install type Standalone (through composer)

I reckon this will be fixed in version 3.0.0 since you're running it on PHP 8.2, and v3 will be PHP 8.2 compatible.

@dingo-d Awesome, thanks for the quick update!

No problem, also there were issues opened with a similar error so you can check them out for more context/information.

@dingo-d is there an eta for release of version 3? thank you

@web-programmer-here We hope by the end of March, but we are not making any promises. There's a lot of work to do still...

This happens as well on PHP 7 now

php -version
PHP 7.4.33 (cli) (built: Feb 15 2023 07:01:39) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies

Same error:
Screenshot 2023-03-30 at 12 48 56

Previously I had solved that with PHP downgrade... but this time it is not PHP version. What else can trigger this?
I did update a few pip libs yesterday and Python, but... that is all unrelated to WPCS, I would assume?

jrfnl commented

@smileBeda That issues doesn't exist on PHP 7. The notice was introduced in PHP 8.1. Are you sure you didn't accidentally update PHP or switch the PHP version being used by PHPCS ?

switch the PHP version being used by PHPCS

maybe.
How could I check that?

Thanks!

jrfnl commented

How could I check that?

No idea as that depends on your system set-up, your OS etc... Can't advise without more info.

MacOs, WPCS installed globally... I will google ;)

Thanks!

@smileBeda are you using PHP Monitor or some other tool to manage multiple PHP versions? I had issues (although on my Windows PC where I used phpenv for PHP version management) where one project was on PHP 7, but the globally applied PHP was 8.

I'd recommend installing WPCS per project, using Composer. Less chance of issues like the above happening.

Sorry the delay here.
which php returns /usr/local/opt/php@7.4/bin/php

php --version returns

PHP 7.4.33 (cli) (built: Apr 26 2023 19:18:43) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies

Yet that ***** brew has messed it up again. Literally every time it is brew. I remain to be enlightened what that is all good for.

brew list php

/usr/local/Cellar/php/8.2.7/.bottle/etc/ (5 files)
/usr/local/Cellar/php/8.2.7/.bottle/var/log/php-fpm.log
/usr/local/Cellar/php/8.2.7/bin/pear
/usr/local/Cellar/php/8.2.7/bin/peardev
/usr/local/Cellar/php/8.2.7/bin/pecl
/usr/local/Cellar/php/8.2.7/bin/phar
/usr/local/Cellar/php/8.2.7/bin/phar.phar
/usr/local/Cellar/php/8.2.7/bin/php
/usr/local/Cellar/php/8.2.7/bin/php-cgi
/usr/local/Cellar/php/8.2.7/bin/php-config
/usr/local/Cellar/php/8.2.7/bin/phpdbg
/usr/local/Cellar/php/8.2.7/bin/phpize
/usr/local/Cellar/php/8.2.7/homebrew.mxcl.php.plist
/usr/local/Cellar/php/8.2.7/homebrew.php.service
/usr/local/Cellar/php/8.2.7/include/php/ (313 files)
/usr/local/Cellar/php/8.2.7/lib/httpd/modules/libphp.so
/usr/local/Cellar/php/8.2.7/lib/php/ (15 files)
/usr/local/Cellar/php/8.2.7/pecl -> /usr/local/lib/php/pecl
/usr/local/Cellar/php/8.2.7/sbin/php-fpm
/usr/local/Cellar/php/8.2.7/share/man/ (8 files)
/usr/local/Cellar/php/8.2.7/share/php/ (159 files)

Removed brew php, WPCS did not work at all anymore.

Bottom line, one more day of headbanging because we are stuck in 2020 and the world evolved (and I learned nothing from the 5 times I did this freaking process already)

🤷
No ones fault but mine, I get that. It still would be nice if in a time where PHP 8+ is the only PHP version that is actually still maintained, the biggest CMS in the world had a Standard that actually would allow PHP 8 instead of expecting us to either stick with 7.x or install develop which does not work, I have tried it multiple times.

jrfnl commented

@smileBeda Could you elaborate on what you mean by the following ?

or install develop which does not work

I don’t recall the specific issue now, but I recall trying it last year and right away running into the next issue which was in some ticket here suggested to be resolved by not using develop 😅

anyway, I’ve set it up from scratch using php 7 again.
And updated the instructions for the install on sublime text since my proposed updates where still pending (I had added them 2 years ago I think)

but it gets a bit “ridiculous” really. We are long past the “grace period” to use or not use php 8.
Most Hosts don’t even allow you anymore to use php 7

I’m aware it’s not your or anyone’s in specific fault. It’s just that the end user is basically forced into using an outdated version of php.
And this should rise some concerns.

for example, why isn’t automattic putting some resources into this process so it can be expedited? Sorry if that’s already the Case and I don’t know. Then, it’s not enough. 😀

for example, why isn’t automattic putting some resources into this process so it can be expedited? Sorry if that’s already the Case and I don’t know. Then, it’s not enough. 😀

You'll need to ask Automattic that, not Juliette, as she is not their employee.

Putting pressure on open-source contributors and blaming them (your wording suggests that WPCS 3.0 not being released is blocking people from using PHP 8) certainly won't make releases happen sooner.

jrfnl commented

@smileBeda Well, the short of it is that there are only so many hours in a day and very few people who seem have the expertise (or are willing to build up the expertise) to maintain tools like this.

Complaining about it is not going to help, it just takes time away from maintainers doing more important stuff than responding to comments like this.

Oh and I'd suggest giving develop another try if the last time you tried was a year ago.