Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:77633 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97016 invoked from network); 25 Sep 2014 20:45:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Sep 2014 20:45:22 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.177 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.212.177 mail-wi0-f177.google.com Received: from [209.85.212.177] ([209.85.212.177:50608] helo=mail-wi0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 50/C0-27297-1EE74245 for ; Thu, 25 Sep 2014 16:45:21 -0400 Received: by mail-wi0-f177.google.com with SMTP id q5so10315484wiv.16 for ; Thu, 25 Sep 2014 13:45:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=t1UT6NBQH3XxZGiUkm3fcft8s/oRBmRLJYWpZoogkks=; b=TwXuVZnXhmmAaPnx5OjqNsek3fjZkzwV/rXF2AGYLvYjYOxNn+eWVMkV72sdOgCY89 nmo5eK4n8qFCHshHbZJsIf3diZ3VfNdxMbzqVpQ9l7Tz4QR57QHTTcdRKbiz/GbBWwyj fw0/K9cA6ieC3uSe7fY2h2u9qv7noTbzfs/1CNbx2PDToWgiKFluXqa/IyUp3+bqZTTe OAbG0sniLKySQeO//Oz3RI/5FHA07gRzeN+8cjrZIuJ3HIB2dA8+mgstDNt2lh0YMyw3 NtXr2FJ320fnXEWe3Xx+TPKWYTifKTHuqGAYc2Y+Nn9Otwm+N8imuz4eCsUHy5+GMOb+ xwxg== MIME-Version: 1.0 X-Received: by 10.194.119.193 with SMTP id kw1mr18966740wjb.82.1411677918169; Thu, 25 Sep 2014 13:45:18 -0700 (PDT) Received: by 10.27.10.95 with HTTP; Thu, 25 Sep 2014 13:45:18 -0700 (PDT) In-Reply-To: References: Date: Thu, 25 Sep 2014 22:45:18 +0200 Message-ID: To: Dmitry Stogov Cc: Leigh , PHP Internals Content-Type: multipart/alternative; boundary=089e01228626d991120503e9e0a6 Subject: Re: [PHP-DEV] [VOTE] Fix list() behavior inconsistency From: nikita.ppv@gmail.com (Nikita Popov) --089e01228626d991120503e9e0a6 Content-Type: text/plain; charset=UTF-8 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: 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 --089e01228626d991120503e9e0a6--