Bug #69676 [Com]: Resolution of self::FOO in class constants not correct

From: Date: Wed, 15 Mar 2017 15:18:33 +0000
Subject: Bug #69676 [Com]: Resolution of self::FOO in class constants not correct
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207856@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69676&edit=1 ID: 69676 Comment by: fredemmott@php.net Reported by: nikic@php.net Summary: Resolution of self::FOO in class constants not correct Status: Assigned Type: Bug Package: Scripting Engine problem PHP Version: master-Git-2015-05-20 (Git) Assigned To: nikic Block user comment: N Private report: N New Comment: As noted on php-internals: PHP7 behavior actually depends on ordering: <?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); Output: string(17) "Foo::A and Bar::C" Previous Comments: ------------------------------------------------------------------------ [2017-01-08 11:08:17] nikic@php.net The particular test script works in PHP 7, but the following still fails: <?php class A { const myDynConst = self::myConst; const myConst = "const in A"; } class B extends A { const myConst = "const in B"; } var_dump(B::myDynConst); var_dump(A::myDynConst); ------------------------------------------------------------------------ [2015-05-20 21:55:04] nikic@php.net Description: ------------ * Resolution of self:: at compile-time for constants currently doesn't seem to happen in PHP 7 * The run-time resolution uses the wrong self:: scope in PHP 7 * The scope is also wrong in PHP 5, but in a different way (depending on whether A:: or B:: is used). Test script: --------------- <?php class A { const myConst = "const in A"; const myDynConst = self::myConst; } class B extends A { const myConst = "const in B"; } var_dump(B::myDynConst); var_dump(A::myDynConst); Expected result: ---------------- string(10) "const in A" string(10) "const in A" Actual result: -------------- PHP 7: string(10) "const in B" string(10) "const in B" PHP 5: string(10) "const in A" string(10) "const in B" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69676&edit=1

« previous php.bugs (#207856) next »