Re: Illegal use of string offset

From: Date: Tue, 27 Apr 2004 11:25:07 +0000
Subject: Re: Illegal use of string offset
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-9583@lists.php.net to get a copy of this message
Hello Christian, thanks for the test Tuesday, April 27, 2004, 12:20:36 PM, you wrote: > Andi Gutmans wrote: >> I made this change back in December. >> I guess I could revert back but I think it makes sense to be strict here. > Reevaluating it I noted the following: > $a = 'foo'; $a['bar']['qux'] = 42; # error > $a = 42; $a['bar']['qux'] = 42; # warning > $a = true; $a['bar']['qux'] = 42; # warning > unset($a); $a['bar']['qux'] = 42; # works > $a = null; $a['bar']['qux'] = 42; # works > $a = false; $a['bar']['qux'] = 42; # works! false should have the same behavior as other scalar values maybe null is discussable but then again it is a value like 0 of true or 42 just with a little specific meaning. > On the other hand > $a = 'foo'; $b = $a['bar']['qux']; # error > $a = 42; $b = $a['bar']['qux']; # works > $a = true; $b = $a['bar']['qux']; # works > unset($a); $b = $a['bar']['qux']; # works > $a = null; $b = $a['bar']['qux']; # works > $a = false; $b = $a['bar']['qux']; # works Having these working without notice/wraning/error if it does without the assignment is a miserable inconsistency. > Let me ask you one question: What it the *real* benefit of making it > fail? Isn't a notice or warning enough safety? > I think this should definitely be more orthogonal, i.e. work (with a > notice or warning) in all cases to avoid WTF. agreed > [ $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. I think we should make [] as string offset an E_STRICT or even E_ERROR because it confuses far too many people especially since we generally have autoconversions and it is not clear what the result of such expressions is without trying them. -- Best regards, Marcus mailto:helly@php.net

« previous php.internals (#9583) next »