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

对这种语法规定,没什么可说的!

打赏

发表评论

电子邮件地址不会被公开。