Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86158 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52057 invoked from network); 11 May 2015 22:45:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 May 2015 22:45:48 -0000 Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.215.46 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.215.46 mail-la0-f46.google.com Received: from [209.85.215.46] ([209.85.215.46:34507] helo=mail-la0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 92/00-51861-B1131555 for ; Mon, 11 May 2015 18:45:47 -0400 Received: by laat2 with SMTP id t2so103834455laa.1 for ; Mon, 11 May 2015 15:45:44 -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:sender:date:message-id:subject:from :to:content-type; bh=1RLqOmqVDnxD4cOn/i85hRi1rZpv0HS5XeGgH4LKsP4=; b=hdnffSLkuK2cFcJyvedIAY1jQlW295AloKvPeVojiKTamQgTNZyxBW06v78pg5fpLN n39Iwq2DvLEhRjmfcxNJFc+fOHW4j1ctLB65q1XfhtyAZBbsJ5nrFWrix9dP/pSPzJr/ zhOjGTBlfES1tuiR5vKPbDhFo9ahDTvwRbBtm+qHxapCBbPeiNFADHLOFyVncjyZaJId DqEtirw0e2RlIs82B536hipwWhMTV4P9ome2C0d6QY+j4xTyGnwrnaihwLHjoMoKFdS2 YgH7wlS/YRFKcL3m+Mgn5sLhI1Tc19nyRiKQnD6otm9DoVffgleUz4dcsGpOdhlFH1O0 Znlw== X-Gm-Message-State: ALoCoQkGJBTDHyx8T+K78yDlPG0PQe+YpiWAKQe024QizZhOxs+VgX8fx9gi4sGjYI6mtP7YmSGA MIME-Version: 1.0 X-Received: by 10.152.43.225 with SMTP id z1mr9173255lal.53.1431383897965; Mon, 11 May 2015 15:38:17 -0700 (PDT) Sender: php@golemon.com Received: by 10.112.11.134 with HTTP; Mon, 11 May 2015 15:38:17 -0700 (PDT) X-Originating-IP: [2620:10d:c082:1055:22c9:d0ff:fe87:295b] Date: Mon, 11 May 2015 15:38:17 -0700 X-Google-Sender-Auth: 3JrrRwo_69KVTDw_Fc8N8mxEqt0 Message-ID: To: PHP internals Content-Type: text/plain; charset=UTF-8 Subject: Undefined variables undefined order From: pollita@php.net (Sara Golemon) http://3v4l.org/uVNIS Prior to PHP 5.1 (and the introduction of compiled variables), the following code would output warnings for the undefined variables in the order they were used: echo $x . $y . $z; However, with the introduction of CVs, we wind up getting the warning for $y, then $x, and finally $z. ((Insert "middle-out" reference from HBO's Silicon Valley, here)) The reason for this, is that ZEND_CONCAT (and indeed, most binary operations) is implemented as a single inline function call: concat_function(EX_VAR(opline->result.var), GET_OP1_ZVAL_PTR(BP_VAR_R), GET_OP2_ZVAL_PTR(BP_VAR_R)); When gcc looks at this function call, it treats the execution order for the arguments as undefined. In practice (at least on 3v4l.org) it ends up evaluating the third argument (OP2) first, then the second argument (OP1), and finally the first argument (result.var). This is perfectly legal as far as GCC is concerned since the result of one function call argument shouldn't have side effects relative to another argument. I'd like to propose making the order of evaluation defined by splitting this into separate statements: zval *op1 = GET_OP1_ZVAL_PTR(BP_VAR_R); zval *op2 = GET_OP2_ZVAL_PTR(BP_VAR_R); concat_function(EX_VAR(opline->result.var), op1, op2); The optimizer should do a proper job of removing the intermediate assignment while keeping the defined resolution order intact. God help us if anyone is actually /depending/ on this behavior... -Sara