Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:9583 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75687 invoked by uid 1010); 27 Apr 2004 11:25:01 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 75663 invoked from network); 27 Apr 2004 11:25:00 -0000 Received: from unknown (HELO shiva.mind.de) (212.42.230.204) by pb1.pair.com with SMTP; 27 Apr 2004 11:25:00 -0000 Received: from BAUMBART (pD95F88DE.dip.t-dialin.net [217.95.136.222]) by shiva.mind.de (Postfix) with ESMTP id 18E9997B4F; Tue, 27 Apr 2004 13:24:59 +0200 (CEST) Date: Tue, 27 Apr 2004 13:25:07 +0200 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <1719688150.20040427132507@marcus-boerger.de> To: Christian Schneider Cc: Andi Gutmans , Curt Zirzow , internals@lists.php.net In-Reply-To: <408E33F4.6050902@cschneid.com> References: <20040427034900.GA31042@bagend.shire> <5.1.0.14.2.20040427104915.02509f58@127.0.0.1> <408E33F4.6050902@cschneid.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Illegal use of string offset From: helly@php.net (Marcus Boerger) 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