[php-src] Issue #15804: [ * ] Historical tails

From: Date: Sun, 08 Sep 2024 12:34:31 +0000
Subject: [php-src] Issue #15804: [ * ] Historical tails
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-247721@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/15804 Author: 6562680 ### Description What is historical purpose of these two: 1. ```php <?php var_dump((bool) '0'); // false (internally intval, ok) var_dump((bool) ''); // false var_dump((bool) '00'); // true (internally intval... what???) ``` Actually i agreed that: - ANY has NULL - TRUE has FALSE - 1/1.1 has 0 and NaN (still is_nan() magic and bugs here, somebody wrote standart that NaN equals nothing even itself... So why only NaN works that way then? Btw, returing NaN from json_decode() seems a great thing like "you cannot encode NaN in your JSON") - 'hello' HAS '' - ['1','2'] HAS [] - Any type has "null/bad equivalent" to reduce count of types at input/output step and detect error via single IF comparison. But why string with '0' equals to false - its not empty string, but empty value inside... Why 2 comparisons? And why 3rd case does the same different way... So, the bug could be safely fixed, because every coder that knows this - write if ('' === $str) so nothing changed, thus who write if (! $str) logically loose nothing, just unexpected bug is fixed silently. Why not? Whats dangerous? 2. ```php <?php // strpos('hello', 'abc') === false ``` I mean, why return "string or false" instead of "string or null" ? Why force to false check via IF preventing to chaining using null-coalesce operator? Am not just about one function, actually tonns of functions in php returning 2 different types to show possible error. Actually its converted to additional check at each step. And in addition some functions raises fatals/warnings, so second check is required. Some functions returned null where NULL is possible value (json_decode()) and needed 3rd check using if (json_last_error())... I mean - whats the idea that function has few ways to indicate errors inside. So, if function throw fatal that can be catched up using "set_error_handler()" globally, and returns null, if ignored - whats wrong? Maybe, to fully safe implement NaN type for any data here? I mean - if something wents wrong - function returned "data mailformed" internal type that equals nothing and breaks any typehint as fast as it can? ### PHP Version PHP 8.0 ### Operating System Win10 x64

« previous php.bugs (#247721) next »