|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-12-10 12:18 UTC] craig at craigfrancis dot co dot uk
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, )
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 03:00:01 2025 UTC |
And the same with ('' == 0)... PHP 7 this would be true, PHP 8 it's false. While I appreciate that's supposed to be false with ('' === 0), the double equals comparison operator is supposed to be equal "after type juggling".