Re: No notices for undefined index

From: Date: Fri, 09 Apr 2010 09:08:33 +0000
Subject: Re: No notices for undefined index
References: 1 2 3 4 5 6 7  Groups: php.general 
Request: Send a blank email to php-general+get-303937@lists.php.net to get a copy of this message
On Fri, 2010-04-09 at 07:52 +0530, kranthi wrote: > >> print $a[0]; // prints 5 > >> print $a[100]; // Notice: Uninitialized string offset: 100 > Yup, this should happen when 5 is treated as an array of characters. > In other words as a string. > $a = '5'; > echo $a[0]; > echo $a[100]; > gives you the expected result > > regarding the original question, i think that the interpreter is > prefilling the variable with null > > $a = 5; > var_dump(isset($a[0])); > var_dump($a[0]); > > since $a[0] is already assigned (to null) the interpreter is not > throwing a notice > > $b = null; > var_dump(isset($b)); > var_dump($b); > If $a is treated as an array of characters, then $a[0] is always the first character, not null. Thanks, Ash http://www.ashleysheridan.co.uk

« previous php.general (#303937) next »