Re: Inconsistency redesign
| From: | mathieu.suen | Date: | Wed, 13 Jan 2010 14:50:18 +0000 |
| Subject: | Re: Inconsistency redesign | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-46690@lists.php.net to get a copy of this message | ||
Etienne Kneuss wrote:
Hello, On Wed, Jan 13, 2010 at 2:36 PM, mathieu.suen <mathieu.suen@easyflirt.com> wrote:The behavior might be documenting but it does not mean that's a good thing. I don't see the point of allowing sizeof on a var that is not an array or object that implement countable.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."
Ho yes but type juggling is pretty mush a big switch casevar_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