Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91102 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35927 invoked from network); 6 Feb 2016 21:39:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Feb 2016 21:39:34 -0000 Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.176 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.192.176 mail-pf0-f176.google.com Received: from [209.85.192.176] ([209.85.192.176:33140] helo=mail-pf0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5B/54-28222-51866B65 for ; Sat, 06 Feb 2016 16:39:34 -0500 Received: by mail-pf0-f176.google.com with SMTP id w123so88404032pfb.0 for ; Sat, 06 Feb 2016 13:39:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-type:content-transfer-encoding; bh=KFE1duarIYmNoWU0+rChpI4tjWqcc/TQ+TM+ChtS2vY=; b=wumTKE8NsH5df60uAXAKXfaQiN4zwXxaWxfAzRzTAeyXAEItTo1lbqmfLS8tI5+pEX EvfdWoCYs5N7ST4vFkKx0Uo7vitRPjlMwcAtjOWjcfrCHsve3MGyM9CT7wfWCNU5jxrc jq3ufHyXnnXN/cnBpNx8Nn96lt7viJECpaBQkWPUIUPMYmu72MwXL76oycyVfSzyrWxy xcC6wDj20oaoSZG+aYhWBh71uORESwTpWbbbs8xHqffLAeyzAO90E9F76SssEQQewZBT 1GAJp0l6FdHKrbvICI2uIcXY+KoumLwKb6+DPc6SJcJfZNirSjWiFqr3FME7pJ1eOe/J 8fqQ== 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:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-type :content-transfer-encoding; bh=KFE1duarIYmNoWU0+rChpI4tjWqcc/TQ+TM+ChtS2vY=; b=B9qgBdTjjz9/+UNFc8ypCmnaDiInSL0Jx+hBNCll9zwkpyV9w32nr3V7tl3EcE52VB 7oYkXszwS4n77jG3I4qTdclF3Y1WfbbAB9W0Rl4A1X5Hi+zmisL9OisgJSLYFXi1UTg0 0YMFmqsSVEbnED6vgava5wzKE2ZLuAyBJIZzuUN7dmouHel6D8Sbv0ZP5OH1rpYbIfEh WFWgXbwCrEOeXbvFi6Zt467X7Qc1cy73AA01HmqpsPVWFyjDbOUzKjYajJUnNnQgzuqU wYR9Zw5rQA0EqSW9yKLBP7e+McwiFEDvDt4Sk6DmnCQ5UxTLQ5l6YxuODJPI0CCqamJ3 7JBQ== X-Gm-Message-State: AG10YOT/zBpbemDMEVsfex/wTDWFDeZ/Hi/UzjhlkkBXdL+NSr+REZBFFE7L01oqkvUgAw== X-Received: by 10.98.13.86 with SMTP id v83mr30748813pfi.162.1454794769507; Sat, 06 Feb 2016 13:39:29 -0800 (PST) Received: from Stas-Air.local ([2602:304:cdc2:e5f0:5d1e:c93d:28c3:f679]) by smtp.gmail.com with ESMTPSA id y86sm33278624pfa.26.2016.02.06.13.39.28 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 06 Feb 2016 13:39:28 -0800 (PST) To: Nikita Popov References: <56A3A01F.1020500@php.net> <56AE8735.4070901@gmail.com> <56AFC8CC.6040201@gmail.com> Cc: Internals X-Enigmail-Draft-Status: N1110 Message-ID: <56B6680F.6070804@gmail.com> Date: Sat, 6 Feb 2016 13:39:27 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Generalize support of negative string offsets From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > if it means one has to take a brief look in the manual. String offset is > *not* the same as array access. > > > What are these subtle differences? Negative indexes, string indexes. Array offset is a variable, so it can be used by-ref, but string offset can not. You can substitute object for array access, and it would work, but not for string offset. You can do $foo[1]++ for arrays, but not for string offsets, same with assign-ops. $foo[1]="bar" works differently - for string offset, it will take only one letter. $foo[1][1] works for arrays but not string offsets. Same for []. $foo[1] = 1 would assign integer for array, but string "1" for strings. It goes deeper. For arrays, $foo[1] is a regular variable, with pretty much everything working on it that works on $foo. For strings, $foo[1] is a very special thing called "string offset", and there are a lot of things that won't work with it. So if you apply your intuition, it'd serve you fine with arrays (can I do ++ on $foo[1]? Sure, why not - it's just a variable). But for string offsets, you have to develop completely different set of rules, as it is a special entity to which regular variable rules do not apply. > I agree that different things should use different syntax. However, the > point here is that all of array access, ArrayAccess and string offset > access are really the same thing and as such should also use the same I think I demonstrated that ArrayAccess and offsets are not the same thing. At least not currently. -- Stas Malyshev smalyshev@gmail.com