Search code examples
phpphp-8loose-typing

PHP 8.0 changes how loose comparison works


Lets have a simple PHP script

<?php
var_dump("php" == 0);

According to official documentation (https://www.php.net/manual/en/types.comparisons.php) , this shoud evaulate into true

BUT It does, for PHP <=7.4, but no for PHP 8.0

In current version of PHP 8 (8.0.0 - 8.0.2) it evaulates to false.

Same script ran in different PHP docker images

Are there any un-documented changes to this functionality or is this a bug? Or am I missing something?

Thank you


Solution

  • PHP Documentation maintainer here, PHP 8 did change the semantics and this is shown in the migration guide. However other parts of the documentations are still lagging behind as we don't have the manpower/time for editing and documenting all the changes related to PHP 8.

    So this is not a bug and more a fact that the current type juggling page is out of date in regards to PHP 8.0.

    It is possible to contribute to the docs via a Pull Request to the GitHub repository.