Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:77638 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 6445 invoked from network); 25 Sep 2014 22:09:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Sep 2014 22:09:54 -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 74.125.82.51 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 74.125.82.51 mail-wg0-f51.google.com Received: from [74.125.82.51] ([74.125.82.51:39302] helo=mail-wg0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 16/50-04944-1B294245 for ; Thu, 25 Sep 2014 18:09:53 -0400 Received: by mail-wg0-f51.google.com with SMTP id b13so259721wgh.10 for ; Thu, 25 Sep 2014 15:09:49 -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=qsAQ+staDKw3QP/jf/L+7os/GqwbNxEZ7QRYIduE0u0=; b=gJ8vTzIZXFiu/NEFzbgB904At4jApwrKw0qjQQsL9OP7IjJHdkms8I5D3MBaJVgHaD 27QIIz6f83G3NWu8E7GwXoiqnK5yDdgXq05rS5LExnGEjhIy9c2Qhmco3+OnTERq/wBO G9kEMdVxWcBpAMBsM7LpMZIMvUkdnpQ69dYXd1EAr8Ar/4XFKMpHO0CECRYEBBpPoCPi kTfxHd+Ed1tSnW/SOxd7PiNSpgUzJEPFU9BNeGNHScbsUtcrOQYGOxNaHDKOv2cAV0IK Qc0z8reumsK1V2HAk0N5oXQNkcz4/ns07Lia/6f0+8UCIqkGPk9oNbdURfYI3bXyf+tf dCQw== MIME-Version: 1.0 X-Received: by 10.195.11.200 with SMTP id ek8mr19519838wjd.85.1411682989795; Thu, 25 Sep 2014 15:09:49 -0700 (PDT) Received: by 10.27.10.95 with HTTP; Thu, 25 Sep 2014 15:09:49 -0700 (PDT) In-Reply-To: <54248E27.1040206@sugarcrm.com> References: <54248E27.1040206@sugarcrm.com> Date: Fri, 26 Sep 2014 00:09:49 +0200 Message-ID: To: Stas Malyshev Cc: Dmitry Stogov , Leigh , PHP Internals Content-Type: multipart/alternative; boundary=047d7b8737622470280503eb0fff Subject: Re: [PHP-DEV] [VOTE] Fix list() behavior inconsistency From: nikita.ppv@gmail.com (Nikita Popov) --047d7b8737622470280503eb0fff Content-Type: text/plain; charset=UTF-8 On Thu, Sep 25, 2014 at 11:50 PM, Stas Malyshev wrote: > Hi! > > > It was on design. list() was intended to support plain arrays only. > > I'm not sure I'm getting this point - why list($a, $b) = $foo is not > just translated as $a = $foo[0], $b = $foo[1], etc.? Is it hard to make > it work that way? > That's exactly what list() does. The only catch is that $foo here is reused multiple times and mustn't be freed in the meantime (for the cases where $foo is some complex expression resulting in an VAR or TMP_VAR operand). That's what the ZEND_FETCH_ADD_LOCK flags for FETCH_DIM_R does - it does $foo[0] without freeing $foo. However back when list() was introduced FETCH_DIM_R didn't support CONST or TMP_VAR operands, so instead these two used a separate FETCH_DIM_TMP_VAR opcode, which supports only arrays and not strings or objects. Support for CONST|TMP in FETCH_DIM_R was only added in PHP 5.5 as part of constant string/array dereferencing. Long story short, because FETCH_DIM_R now supports CONST and TMP_VAR operands, we can always use it and FETCH_DIM_TMP_VAR can be dropped - that's all that has to be done in order to always support strings and objects in list(). (I've linked a patch for this previously, see https://github.com/nikic/php-src/compare/stringOffsetsInList). If I understood it correctly, then Dmitry's alternative is to add support for CV and VAR operands to FETCH_DIM_TMP_VAR and always use that for list(). This avoids having to check the ZEND_FETCH_ADD_LOCK flag in FETCH_DIM_R. However I don't think that this optimization is related to whether or not we support strings and objects. We can have a separate opcode only for list() in either case, no matter which choice is made here. Nikita --047d7b8737622470280503eb0fff--