Re: Illegal use of string offset

From: Date: Tue, 27 Apr 2004 10:20:36 +0000
Subject: Re: Illegal use of string offset
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-9582@lists.php.net to get a copy of this message
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! 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 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. [ $a = 'foo'; $a['bar'] = 42; has an even weirder behaviour: It results in the string '4oo'... ] - Chris

« previous php.internals (#9582) next »