|
Posted by gosha bine on 04/24/07 09:27
On 24.04.2007 02:49 ljb wrote:
> I was a bit surprised to find that indexing some non-arrays as if they were
> arrays does not even raise a Notice message. This works for NULL, integer,
> and floats at least. (PHP-5.2.1)
>
> error_reporting(E_ALL+E_STRICT);
> $arry = array(1=>1);
> $nullvar = NULL;
> $intvar = 1;
>
> echo $arry[1]; # Echos 1
> echo $arry[2]; # Notice: undefined offset.
> echo $nullvar[1]; # Echos nothing and no Notice.
> echo $intvar[0]; # Ditto
> echo $intvar[1]; # Ditto
>
> The manual says that if you convert integer to array, you get an array with
> one element at [0]. But that isn't what is happening here, because
> $intvar[0] is NULL, not 1, and $intvar[1] does not result in an undefined
> offset notice. Instead, I get an array with NULL for any index.
>
> I actually find this behavior useful, but I don't like depending on what
> seems to be a quirk.
this is the way it's coded in zend engine: reading indexed access to
scalars returns null. I agree that this behaviour is confusing, and it
doesn't seem to be documented. Did you consider filing a bug at php.net?
--
gosha bine
extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
[Back to original message]
|