Re: No notices for undefined index

From: Date: Thu, 08 Apr 2010 20:09:11 +0000
Subject: Re: No notices for undefined index
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-303925@lists.php.net to get a copy of this message
Bob McConnell wrote: > In the first case, $a=5 creates a multi-typed variable. The interpreter > makes its best guess how the next two expressions should be interpreted. > In both cases, they look a lot like an index into a character array > (string), and 'test' evaluates numerically to zero. Both are valid > offsets for a string, so no messages are generated. > > In the second case, $a is explicitly declared as an array. This give the > interpreter a lot more detail to work from. The two expressions are now > an index and a key for the array. But both of them evaluate to offsets > that have not been assigned, which raises a flag and creates the > warnings. > > Such are the joys of loosely typed languages. > > Bob McConnell Yes, this is what I was thinking as well, however: $a=5; print $a[0]; // if it is index 0 then it should print 5 yes? print $a[100]; // there is no index 100 so why no notice? -- Thanks! -Shawn http://www.spidean.com

« previous php.general (#303925) next »