Re: Re: foreach with null

From: Date: Wed, 26 Oct 2005 23:17:11 +0000
Subject: Re: Re: foreach with null
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-19751@lists.php.net to get a copy of this message
Ilia Alshanetsky wrote: > Greg Beaver wrote: > >>amen, this behavior makes no sense even though sizeof() is an alias to >>count(). sizeof('this') and sizeof('this long thing') are both 1, which >>makes no sense. I would go so far as to say a E_NOTICE is more >>appropriate than E_STRICT - you should only be using count() for >>arrays/objects. > > > Actually this result makes perfect sense since type conversion changes > string into array('your string') and does a count of that, which is 1. Yes, it makes sense from this perspective, but from a real-life programming perspective it is 1) useless - count() provides no useful information about strings 2) potentially buggy. For instance, PEAR's XML_Unserializer (XML_Serializer package) represents XML elements with simple text node children as a string, and tags with anything else (attributes, child elements) as an array. Improperly written code that uses count() without checking is_array() would happily run with no warning whatsoever. However, imho it would make PHP more robust if the logical error condition were also a language error, that's all. Greg

« previous php.internals (#19751) next »