Bug #80502 [NEW]: Comparison of empty string to 0

From: Date: Thu, 10 Dec 2020 12:18:56 +0000
Subject: Bug #80502 [NEW]: Comparison of empty string to 0
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230993@lists.php.net to get a copy of this message
From: craig at craigfrancis dot co dot uk Operating system: N/A PHP version: 8.0.0 Package: *General Issues Bug Type: Bug Bug description:Comparison of empty string to 0 Description: ------------ Maybe related to RFC "string_to_number_comparison"? In PHP 7 the comparison ('' < 0) would convert the empty string to 0, then return false. But in PHP 8.0.0, the empty string is now considered less-than 0? Common issue for HTML forms, which provide all values as strings, and a blank number field is effectively seen as 0 - e.g. entering a time with separate fields (hours and minutes), and the user does not enter a value in the seconds field... yes, you could cast the value to an integer, but a lot of websites out there don't. Test script: --------------- var_export([ ('' < 0), ('1' < 0), ('0' < 0), ]); Expected result: ---------------- array ( 0 => false, 1 => false, 2 => false, ) Actual result: -------------- array ( 0 => true, 1 => false, 2 => false, ) -- Edit bug report at https://bugs.php.net/bug.php?id=80502&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=80502&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=80502&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=80502&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=80502&r=needscript Try newer version: https://bugs.php.net/fix.php?id=80502&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=80502&r=support Expected behavior: https://bugs.php.net/fix.php?id=80502&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=80502&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=80502&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=80502&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=80502&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=80502&r=dst IIS Stability: https://bugs.php.net/fix.php?id=80502&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=80502&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=80502&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=80502&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=80502&r=mysqlcfg

« previous php.bugs (#230993) next »