php-src
php-src copied to clipboard
Empty("0")
Description
Is it reasonable to hope that the illogical behavior of the empty() will one day be corrected?
var_dump(empty(null)); // bool(true)
var_dump(empty('')); // bool(true)
var_dump(empty('0')); // bool(true) <--- THIS
var_dump(empty('0.0')); // bool(false)
var_dump(empty(' ')); // bool(false)
var_dump(empty('false')); // bool(false)
var_dump(empty([])); // bool(true)
var_dump(empty(0)); // bool(true)
var_dump(empty(0.0)); // bool(true)
var_dump(empty(false)); // bool(true)
String '0' is not empty really, but the language construct empty considers this to be otherwise.
Perhaps one day it will become a function?
No, it is not realistic because of the impressive BC break that comes along with it, if you disagree with this then you can make an RFC and try to make your case on the internals mailing list but beyond that it is not a realistic consideration as of current.