Re: Inconsistency redesign

From: Date: Wed, 13 Jan 2010 13:50:17 +0000
Subject: Re: Inconsistency redesign
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-46686@lists.php.net to get a copy of this message
Hello, On Wed, Jan 13, 2010 at 2:36 PM, mathieu.suen <mathieu.suen@easyflirt.com> wrote: > Hi, > > I came across this: > > echo sizeof(array()); > echo sizeof(""); > $a = ""; php.net/count: "If var is not an array or an object with implemented Countable interface, 1 will be returned. There is one exception, if var is NULL, 0 will be returned." > var_dump( empty($a)); > $a = array(); > var_dump(empty($a)); php.net/empty empty($var) is basically an !isset($var) || !$var it's not related to count in anyway. > > So funny! How something can have a size greater than 0 but still be empty? > I think PHP is reinventing the inconsistency word. I think such comments are pretty useless. Try coming with a viable solution as a patch instead. > > But then let assume that empty is just making a cast in array. If you assume wrong, you can derive all kind of madness. > $a = ""; > empty($a) //true > empty((array)$a) //false > > Ok so empty is big ugly switch case on type. No, it's a boolean check, with type juggling involed, see above. > > empty(0); //true > empty(45); //false > > Wooow reinventing emptiness on number.... > > -- Mathieu Suen > > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Etienne Kneuss http://www.colder.ch

« previous php.internals (#46686) next »