Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91208 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83724 invoked from network); 11 Feb 2016 14:59:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Feb 2016 14:59:15 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.50 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.50 mail-wm0-f50.google.com Received: from [74.125.82.50] ([74.125.82.50:37900] helo=mail-wm0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E2/DB-25203-1C1ACB65 for ; Thu, 11 Feb 2016 09:59:14 -0500 Received: by mail-wm0-f50.google.com with SMTP id p63so71961434wmp.1 for ; Thu, 11 Feb 2016 06:59:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:cc:message-id:date:user-agent :mime-version:in-reply-to:content-type:content-transfer-encoding; bh=/ap8BGtEoMqN13KqyxUDPlAAZtvP2iWyaf56CgHwTl8=; b=ONylkHlQ5Qeb0h9hg5I/p38DOBLBnL95q8MpRDLKvL/qxfb4eEuuZ7KdW3+K2xaP93 6NrwLwbUCSt74vXcvXsdibqJlEjKv1KwXoT1RI0JErc6DFnDXIJNTs/fhYzXtl7Qd1x6 NE54hFBD9KuX0XmpOFeLVtQyDaX4z8bzEWoaXDL6VrHrcRZze2W6cd27MnYri1m3u1cZ RN1WBcMF5i3MX/olLjtdB7Lp21nTZEjHcybPjBxoUQnHzqMqSCn6RRdHebYkl5CW4OHp Sew+aeLiHIX+YthTZ5jJg62wpZbhWOyI0K39f58NbSCcUtA4P8wTUTl97jnASXKdzXlq qDFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:cc:message-id:date :user-agent:mime-version:in-reply-to:content-type :content-transfer-encoding; bh=/ap8BGtEoMqN13KqyxUDPlAAZtvP2iWyaf56CgHwTl8=; b=RscLUdPywOj1KCneVdhSqelzQOzT35CpHzBKmUx3wwg330BV5GBm1fTHiXwv345VqK ig6Wy2/cLtH9ozLuOOzhwqBuQTYyIzAAnfPQ1Gu55On73ZSaTnSCNFyBSWzRoyTntDtx TQQu0g34DEQ5drLco4eLkUDo18DF5MNMEKCOQaha0WGT/ZT9TTdJgI2awDeF7vAJhtff W27bqC+gEAUoenZ9drGwtc6Sg5nmnE/sU/ms7HhENsm1gzkcMSgxD7zSiRRvcc9DTx5u qpQItKYiHavuymZ5zSNuLwHp2GNUezJD22D5AHTs9JN3vMJ6R3B2mjeJmaQ+lTv1o7Xp G9Sg== X-Gm-Message-State: AG10YOTdcsu/cTNtjW/WPk834dvQnfhS2Pns+sxRvkyuC+Eg9xXSr9gmtvFP+SILgKktVQ== X-Received: by 10.194.22.167 with SMTP id e7mr54616893wjf.29.1455202750450; Thu, 11 Feb 2016 06:59:10 -0800 (PST) Received: from [192.168.0.152] ([93.188.182.58]) by smtp.googlemail.com with ESMTPSA id g126sm12061139wmf.16.2016.02.11.06.59.09 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 11 Feb 2016 06:59:09 -0800 (PST) To: PHP internals References: <56A3A01F.1020500@php.net> <56BB4A5F.3060906@php.net> <56BC29C8.9070308@gmail.com> <56BC3372.1010308@gmail.com> <56BC7BB6.6070705@gmx.de> <56BC829C.1040608@gmail.com> Cc: Nikita Popov Message-ID: <56BCA158.9060005@gmail.com> Date: Thu, 11 Feb 2016 14:57:28 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Generalize support of negative string offsets From: rowan.collins@gmail.com (Rowan Collins) Nikita Popov wrote on 11/02/2016 13:14: > The issue here is not an inherent problem with string offsets, it's > simply yet another artifact of PHP's overly lenient nature. If I > create an IntArray class that implements ArrayAccess, I don't think > you would be much surprised if doing $intArray[$i] = "123abc" would > end up storing the value int(123), as this just conforms to PHP's > usual silent, lossy type conversion semantics. It's the same with > string offsets, just with the conversion happening from string to > single-character-string. Eh, I can see the logic, but there is no such type as "single-character string"; that's why I said PHP's type system was to blame - if there was a "char" type, things become simpler to explain: - the assignment case would be a case of implicit conversion from string to char - the $foo[0][0] case could give an error that you can't offset a char, and "$bar = $foo[0]; echo $bar[0];" would be able to give the same error I'd like to stress that these are just a couple of examples; I'm sure there are other "anomalies". > Just having a different syntax, writing $foo{0} = 'zzz' instead of > $foo[0] = 'zzz' does not make the implicit truncation behavior any > more obvious or reasonable. No, but it gives a general warning to the reader that this is a bit like array access, but not quite. > If we want to actually make it less confusing, what we should do is > throw a warning if such a truncation occurs. And that's something that > can be done independently of syntax. Agreed. > Instead we should strive to make these things work as expected. Agreed for the cases where it is obvious what is expected. Sometimes, though, I think it is not reasonable to expect the same behaviour as for an array, and so "striving to make string offsets work well" and "striving to make string offsets work the same as array offsets" are different, and possibly conflicting, goals. Regards, -- Rowan Collins [IMSoP]