|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-05-20 21:55 UTC] 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"
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 16:00:01 2025 UTC |
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);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"