I'm working on making CodeIgniter 3 compatible with PHP 8.2. The primary obstacle seems to be rampant assignment of dynamic properties to various class instances, which was deprecated in 8.2. To identify situations where this happens, I'm relying on phpstan.

I've run into a confusing issue where phpstan on MacOS (I like to develop with my laptop on the couch next to the heater when it's cold) is returning a lot more errors than it does on Ubuntu. I'm running this exact same script on both machines:

mkdir ci3-dev
cd ci3-dev
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
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');"
./composer.phar require --dev phpstan/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

On Ubuntu I get about 1040 errors, on MacOS it's 1830, primarily because phpstan is complaining it doesn't see CI_DB class declaration. Both machines have PHP 8.2.3 installed Here are the errors from one file for illustrative purposes. Ubuntu has fewer errors 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.
 ------ -----------------------------------------------------

MacOS has a lot more:

 ------ ---------------------------------------------------------------------
  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.
 ------ ---------------------------------------------------------------------

Yes, I do see the link they offer in the errors, but I don't see any reason why this would cause things to behave differently between Ubuntu and MacOS.

Does anyone have an idea why this might be happening?

Note, it's been a bit quiet around here so I posted this same question on Stack Overflow here.

    Write a Reply...