|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-11-27 14:37 UTC] owlet at avtovokzaly dot ru
Description:
------------
Sometimes we need to define constants directly in trait. Now it is impossible and can be done throw namespace constants, for example, But this replacement very uncomfortable.
Test script:
---------------
trait A {
const CONST_A = 'value of A::A';
}
class B {
use A;
public static function getA()
{
return self::CONST_A;
}
}
echo B::getA();
Expected result:
----------------
value of A::A
Actual result:
--------------
PHP Fatal error: Traits cannot have constants in php shell code on line 2
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 04:00:02 2025 UTC |
Or, perhaps, to use an expression for compiler in the same manner as for methods: use A, B { B::CONST_A insteadof A; }