Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98536 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42507 invoked from network); 15 Mar 2017 12:25:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Mar 2017 12:25:34 -0000 Authentication-Results: pb1.pair.com header.from=david.proweb@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=david.proweb@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.44 as permitted sender) X-PHP-List-Original-Sender: david.proweb@gmail.com X-Host-Fingerprint: 209.85.213.44 mail-vk0-f44.google.com Received: from [209.85.213.44] ([209.85.213.44:34832] helo=mail-vk0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A2/6E-38004-DB239C85 for ; Wed, 15 Mar 2017 07:25:33 -0500 Received: by mail-vk0-f44.google.com with SMTP id x75so7396909vke.2 for ; Wed, 15 Mar 2017 05:25:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=i1FXr7/ljqmZlPn1MFBuAq1+6Hm9lYqOozuuUmPCwTk=; b=lMxgCKz+8YirVNpGUl8fL659I6r0prpLhMqEqZCUIHYso+gKmbN03tgfK4WCQV40rD j/cQsmMStw7AlfhqudUyGMSLWmM8XweHg+M5XJNt65Stb3QIySjFWfdgthVt2XXeOlRI pggOyTzfEpNZ19uGJgNRfKnXFk2gPVXVCcH4HVE7tYgBoxsfQYiZKvn2encBeMNfgzQ+ 4UX9qbCiQ2b0vl763oZcHH0Awnfd3KoadbdGYNom44acamexjGK9ktcu/+Up2PyEYjdJ FLIkomRWa+IISDGh3fCP9PRBTZQWz/rf56Q9GeSH3pGpr/LEjIlMvGKF7G6JZWSwzX7N y/Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=i1FXr7/ljqmZlPn1MFBuAq1+6Hm9lYqOozuuUmPCwTk=; b=unAQaOx96TNmlPtcatVFxx2yHIMfEvNs3uXuDcWlMnse7BVWvpqx/SbaoIdX0I5GFI LQv1ceUE3jQvci1/DyPTd90lup5ZJFr1cMpp5yhmprL+LSy/6ULxF90Gg1VwaF7kwTz2 XFpOURXkcGCohtPWkk2/t2PdTFDhVRY4fPUqD95+6StzDz8ede1agNKI/fOBAJxFkK50 baCWt3Hber4K/PtuVdQ7RN9Z1sz4Qh5CqN6TuFyg7rhPINAVm2kThi+3Sw+jx6l7Qo8x LG3ku9giJkxOY1e7fV/Su0WE3PmjzGnvk4vnMdton4cmw9kXkHa9tWZ4el4IZMJenwva HK+Q== X-Gm-Message-State: AFeK/H3DQYiBoARQ1QCGnJBtH5yoVi3fIBPf1t7kffRqtmpMV181hD6wAM/PUVl6TLihgfD/+ljE3wsOEscJUQ== X-Received: by 10.31.77.196 with SMTP id a187mr818065vkb.99.1489580730416; Wed, 15 Mar 2017 05:25:30 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.132.204 with HTTP; Wed, 15 Mar 2017 05:25:09 -0700 (PDT) In-Reply-To: References: Date: Wed, 15 Mar 2017 09:25:09 -0300 Message-ID: To: Nikita Popov Cc: Sara Golemon , PHP internals Content-Type: multipart/alternative; boundary=001a114dc58c4d169f054ac40afd Subject: Re: [PHP-DEV] Unexpected results from constant folding From: david.proweb@gmail.com (David Rodrigues) --001a114dc58c4d169f054ac40afd Content-Type: text/plain; charset=UTF-8 Just to make simpler to visualize this issue: https://3v4l.org/ZhYlm ```php class Foo { const A = 'Foo::A'; const B = self::A . ' and ' . self::C; const C = 'Foo::C'; } class Bar extends Foo { const A = 'Bar::A'; const C = 'Bar::C'; } var_dump(Bar::B); ``` You should note that: PHP 7.0 to 7.1.2 => Foo::A and Bar::C > It will give a result like a self::A and static::C (currently last one is impossible); PHP 5.6 to 5.6.30 => Bar::A and Bar::C > It will give a result like a static::A and static::C; hhvm 3.12.14 to 3.18.1 => Foo::A and Foo::B > It will give a result like should be expected on code (both from self:: that is the Foo class); 2017-03-15 7:36 GMT-03:00 Nikita Popov : > On Wed, Mar 15, 2017 at 3:43 AM, Sara Golemon wrote: > > > This comes in thanks to my old friend Fred Emmott on the HHVM project: > > https://3v4l.org/vUHq3 > > > > class Foo { > > const A = 1 << 0; > > const B = self::A | self::C; > > const C = 1 << 1; > > > > } > > > > class Bar extends Foo { > > const A = 1 << 2; > > const C = 1 << 3; > > } > > > > var_dump(decbin(Bar::B)); > > // HHVM result: 11 > > // PHP5 result: 1100 > > // PHP7 result: 1001 > > > > HHVM's result is clearly correct as `self::` refers to the defining > > class and so should bind to Foo's values for A and C. > > PHP5's result is at least rationally viable, although it effectively > > redefines `self::` to the semantics of `static::` just for this case. > > PHP7's result is... well, I can imagine how it occurs, but it can't be > > called correct by any measure. > > > > Opinions on the right thing to do here? > > a) Leave it alone because it's been that way since 7.0 > > b) Revert to php5 behavior > > c) Match HHVM's behavior > > > > I vote C because that's the semantic meaning of self:: and we should > > respect PHP's own language rules. > > Barring that, I'd be okay with B as it's at least explainable without > > too much mental gymnastics. > > I straight up veto A. That's just cray-cray. > > > > Yes, this should behave as C. See also https://bugs.php.net/bug.php? > id=69676 > for an existing bug report on the topic. > > I think in 7.1 it might be even fairly simple so fix this: IIRC we now > store the defining CE on inherited constants, so we should know the scope > to resolve against. > > Nikita > -- David Rodrigues --001a114dc58c4d169f054ac40afd--