Bug #79592 [NEW]: Converting string to bool when "0" passed
From: 6562680 at gmail dot com
Operating system: Win10
PHP version: 7.3.17
Package: Filter related
Bug Type: Bug
Bug description:Converting string to bool when "0" passed
Description:
------------
I know, i know...
"you should use strict_types()" and so...
But really guys, why, exactly, why string "0" will be converted to false
while calling (bool) ?
Please :///
Once i found same joke while comparing two values on usort(), fixed...
now i remember used everywhere (! $string) and confused... little bit.
Test script:
---------------
function (string $name) {
if (! $name) {
// nice one, junior, you'll lose "0" right here
// please rewrite your project and use ('' !== $name) or be fired
throw new \InvalidArgumentException('String should be not empty');
}
// some code
}
Expected result:
----------------
(bool) 0 === false
(bool) "0" === true
(bool) (string) 0 === true
...
Actual result:
--------------
(bool) 0 === false
(bool) "0" === false
(bool) (string) 0 === false
...
--
Edit bug report at https://bugs.php.net/bug.php?id=79592&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79592&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79592&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79592&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79592&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79592&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79592&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79592&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79592&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79592&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79592&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79592&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79592&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79592&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79592&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79592&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79592&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79592&r=mysqlcfg
Thread (7 messages)
- 6562680 at gmail dot com