Re: Illegal use of string offset

From: Date: Tue, 27 Apr 2004 12:42:05 +0000
Subject: Re: Illegal use of string offset
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-9586@lists.php.net to get a copy of this message
On Tue, Apr 27, 2004 at 02:16:43PM +0200, Marcus Boerger wrote: > Hello Christian, > > Tuesday, April 27, 2004, 1:34:47 PM, you wrote: > > > Marcus Boerger wrote: > >>>[ $a = 'foo'; $a['bar'] = 42; has an even weirder behaviour: It > >>>results > >>>in the string '4oo'... ] > >> > >> That's a pretty. It is using 'bar' as a sting index to 'foo' > >> and to do > >> this it needs to convert 'bar' to an integer. The rest is obvious. > > > So you find it obvious that 42 is cast to string and the first character > > is used as replacement? Wasn't obvious to me before I tried it :-) > > That's what i meant it confuses far too many people and doesn't even make > real sense. For example converting 42 into chr(42) and setting it would > follow the same autoconversion logic. Hence a hint of kind E_STRICT would > be very good. I know I have no karma here, but anyway: If you want to give people a hinting they access their stuff in a wrong way *and* you want it in a consistent way: why not throw an E_STRICT (or maybe even an E_NOTICE) when accessing anything via [] that is not array? $a = null; $a['foo']; -> should give an E_STRICT (if not an E_NOTICE) $a = false; $a['foo']; -> should give an E_STRICT (if not an E_NOTICE) $a = "FOO"; $a['foo']; -> should give an E_STRICT (if not an E_NOTICE) $a = array(); $a['foo']; -> gives an E_NOTICE because of "undefined index 'foo'" $a = array('foo'=>'FOO'); $a['foo'] -> obviously okay just my few p. messju > marcus

« previous php.internals (#9586) next »