Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:77635 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1719 invoked from network); 25 Sep 2014 21:47:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Sep 2014 21:47:41 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.175 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.175 mail-vc0-f175.google.com Received: from [209.85.220.175] ([209.85.220.175:60979] helo=mail-vc0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 27/81-27297-C7D84245 for ; Thu, 25 Sep 2014 17:47:40 -0400 Received: by mail-vc0-f175.google.com with SMTP id hy4so1157816vcb.20 for ; Thu, 25 Sep 2014 14:47:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=ccdvtOaLQ2k1ykbjertoZbobzig0/uOQme2vRh+mMzk=; b=J/Z3/z+kFHPxLQvk0dbn5g9s9bChJyNi6GEayAKuebRrZIq/CxfXi8izuG1CzHxS0h Wfc0wyvXqMtmmoRLYTSPtiuh6DIGtjxwZGXDHeyoXVEBvFkwcmgxVw+u/1j5oJV1aIpn RthLfIlZlwK+OdyImCGc8j2H9Sas2iEbsBbNvytOs2OzBLxUNKW2LJiZyv7hDVcNV56l iBNiLBMItuYsXLT98HoeAm39a8HGdkLwJwPtbq/UANN5qJ86c/ME44CNlGnUvASs2E1d 8ddT1y7qJ/uJoU9ucIh2MF1NYflZtCQB4Xe3V5pfmcw6M06HATb82Sa6L0vjCsl30Uxy D50g== X-Gm-Message-State: ALoCoQmESsULNfPnfNWrOzMqkbgBC+09aH/TVy4gaFj52M+n8Pfi+yYGGRvLVgeseX/orLVatD+nJPHbjAO4iqpVc7dQo92jBs90xSNdRHEUm3l0PoDuQf7yIFXX26uy/QZtNomnhGfMVHbiMnnt6hGgDrwSw9lRCw== MIME-Version: 1.0 X-Received: by 10.52.146.17 with SMTP id sy17mr10635289vdb.29.1411681657326; Thu, 25 Sep 2014 14:47:37 -0700 (PDT) Received: by 10.52.158.197 with HTTP; Thu, 25 Sep 2014 14:47:37 -0700 (PDT) In-Reply-To: References: Date: Fri, 26 Sep 2014 01:47:37 +0400 Message-ID: To: Nikita Popov Cc: Leigh , PHP Internals Content-Type: multipart/alternative; boundary=bcaec52d5987b8a6010503eabf89 Subject: Re: [PHP-DEV] [VOTE] Fix list() behavior inconsistency From: dmitry@zend.com (Dmitry Stogov) --bcaec52d5987b8a6010503eabf89 Content-Type: text/plain; charset=UTF-8 It was on design. list() was intended to support plain arrays only. Thanks. Dmitry. On Fri, Sep 26, 2014 at 12:45 AM, Nikita Popov wrote: > On Thu, Sep 25, 2014 at 10:32 PM, Nikita Popov > wrote: > >> On Thu, Sep 25, 2014 at 1:15 PM, Dmitry Stogov wrote: >> >>> disabling string handling would allow make operation simpler and would >>> improve regular access to array elements. >>> We won't need to check for (opline->extended_value & ZEND_FETCH_ADD_LOCK) >>> in FETCH_DIM_R handler. >>> However, it's going to be very small improvement, and I don't care a >>> lot. :) >>> >>> enabling string handling would require complication of >>> ZEND_FETCH_DIM_TMP_VAR handler (for strings support). >>> It's going to make list() handling a bit slower, but not significantly. >>> >>> my choice +1 for disabling. >>> >> >> Could you please clarify why removing string support would make the >> operation simpler? I voted for always supporting strings because I thought >> that is the option that simplifies things - in particular it would allow >> use to drop the FETCH_DIM_TMP_VAR opcode and always go through FETCH_DIM_R >> instead. Sample patch here: >> https://github.com/nikic/php-src/compare/stringOffsetsInList Or did I >> miss something and we can't do that? >> >> Nikita >> > > I'd like to add that the FETCH_DIM_TMP_VAR opcode also provides incorrect > results if objects are used. list() generally accepts objects implementing > ArrayAccess, but if the object happens to be a TMP_VAR and > FETCH_DIM_TMP_VAR is used instead of FETCH_DIM_R, you'll just get a NULL > result: > > > class Arr implements ArrayAccess { > private $arr; > public function offsetGet($k) { return $this->arr[$k]; } > public function offsetSet($k, $v) { $this->arr[$k] = $v; } > public function offsetExists($k) { return isset($this->arr[$k]); } > public function offsetUnset($k) { unset($this->arr[$k]); } > } > > $arr = new Arr; > $arr[0] = 'foo'; > $arr[1] = 'bar'; > > list($a, $b) = $arr; > var_dump($a, $b); // foo, bar > > // (object) forces TMP_VAR > list($a, $b) = (object) $arr; > var_dump($a, $b); // NULL, NULL > > So to handle that case we'd already have to extend the FETCH_DIM_TMP_VAR > handler to support objects in addition to arrays. At which point I don't > really see the point of making this a special case and would always use > FETCH_DIM_R instead (which already has all the necessary code to support > arrays, objects and strings). > > Nikita > --bcaec52d5987b8a6010503eabf89--