php-src icon indicating copy to clipboard operation
php-src copied to clipboard

Empty("0")

Open KarelWintersky opened this issue 3 weeks ago • 1 comments

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?

KarelWintersky avatar Nov 09 '26 08:11 KarelWintersky

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.

kallesommernielsen avatar Nov 09 '26 08:11 kallesommernielsen