I've forked CodeIgniter 3 to work on PHP 8.2 compatibility. I'm using PHPStan for static analysis to try and identify all the referencees to undefined class properties, which seems to be the primary shortcoming. Unfortunately, I'm getting very different output on MacOS than on Ubuntu, and I don't know why. It would appear that phpstan on MacOS is failing to recognize the definition of one class, CI_DB
, and this is leading to about 800 more errors being reported. My question is why are there more errors on MacOS than on Ubuntu and how do I remedy this problem?
NOTE: Both machines have PHP 8.2 installed:
MacOS::
$ php -v
PHP 8.2.3 (cli) (built: Feb 24 2023 10:25:18) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.3, Copyright (c) Zend Technologies
with Zend OPcache v8.2.3, Copyright (c), by Zend Technologies
Ubuntu:
$ php -v
PHP 8.2.3 (cli) (built: Feb 14 2023 16:57:50) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.3, Copyright (c) Zend Technologies
with Zend OPcache v8.2.3, Copyright (c), by Zend Technologies
To reproduce the problem, you can run this script from the command line:
mkdir ci3-dev
cd ci3-dev
### fetch CI3
curl -o ci.zip https://codeload.github.com/bcit-ci/CodeIgniter/zip/refs/heads/develop
unzip ci.zip
mv CodeIgniter-develop codeigniter
rm ci.zip
### install composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
### install phpstan
./composer.phar require --dev phpstan/phpstan
### configure and run phpstan
echo -e "parameters:" >> ci.neon
echo -e "\tlevel: 2" >> ci.neon
echo -e "\tpaths:" >> ci.neon
echo -e "\t\t- codeigniter" >> ci.neon
echo -e "\texcludePaths:" >> ci.neon
echo -e "\t\tanalyse:" >> ci.neon
echo -e "\t\t\t- codeigniter/tests" >> ci.neon
echo -e "\t\t\t- codeigniter/user_guide_src" >> ci.neon
vendor/bin/phpstan clear-result-cache -c ci.neon
vendor/bin/phpstan analyse -c ci.neon > phpstan.txt
NOTE: This code may get out of date if composer or CI3 gets updated. You might need to manually retrieve CI3 or adjust the composer installation steps if this script has problems.
The output of the phpstan analysis can be found in ci3-dev/phpstan.txt. On my Ubuntu machine, this reports 1044 errors. On my MacOS machine, it reports 1830 errors. I've got a zip file with phpstan-ubuntu.txt, phpstan-mac.txt, and a diff of the two files, phpstan-diff.txt but these files are about 200K each, so too large to post here. I offer this one example difference to try and express what I think the primary problem is, namely that MacOS somehow doesn't see the declaration of the class CI_DB
. The ubuntu output for system/libraries/Profiler.php:
------ -----------------------------------------------------
Line system/libraries/Profiler.php
------ -----------------------------------------------------
166 Call to an undefined method object::elapsed_time().
521 Access to an undefined property object::$lang.
521 Access to an undefined property object::$lang.
521 Access to an undefined property object::$lang.
521 Access to an undefined property object::$lang.
521 Access to an undefined property object::$lang.
------ -----------------------------------------------------
is quite short, whereas the MacOS output is quite a bit longer because it somehow can't find CI_DB:
------ ---------------------------------------------------------------------
Line system/libraries/Profiler.php
------ ---------------------------------------------------------------------
166 Call to an undefined method object::elapsed_time().
207 Class CI_DB not found.
Learn more at https://phpstan.org/user-guide/discovering-symbols
215 Class CI_DB not found.
Learn more at https://phpstan.org/user-guide/discovering-symbols
247 Access to property $queries on an unknown class CI_DB.
Learn more at https://phpstan.org/user-guide/discovering-symbols
248 Access to property $query_times on an unknown class CI_DB.
Learn more at https://phpstan.org/user-guide/discovering-symbols
260 Access to property $database on an unknown class CI_DB.
Learn more at https://phpstan.org/user-guide/discovering-symbols
261 Access to property $queries on an unknown class CI_DB.
Learn more at https://phpstan.org/user-guide/discovering-symbols
264 Access to property $queries on an unknown class CI_DB.
Learn more at https://phpstan.org/user-guide/discovering-symbols
271 Access to property $queries on an unknown class CI_DB.
Learn more at https://phpstan.org/user-guide/discovering-symbols
273 Access to property $query_times on an unknown class CI_DB.
Learn more at https://phpstan.org/user-guide/discovering-symbols
521 Access to an undefined property object::$lang.
521 Access to an undefined property object::$lang.
521 Access to an undefined property object::$lang.
521 Access to an undefined property object::$lang.
521 Access to an undefined property object::$lang.
------ ---------------------------------------------------------------------