test(trait): add test case for trait class constant inheritance behavior

- Create test verifying trait class constants remain bound to composing class
- Add test with ClassIdentityTrait using __CLASS__ and self::class
- Include Base class that uses the trait and Child extending Base
- Verify magicClass() returns "Base" instead of "Child"
- Verify selfClass() returns "Base" instead of "Child"
- Add expected output showing correct binding behavior
pull/47/head
韩天峰 2 weeks ago
parent ca41af9bb5
commit 8d4801ebd2
  1. 36
      tests/compiler/trait/trait-class-constant-inherited.phpt

@ -0,0 +1,36 @@
--TEST--
Trait class constants remain bound to the composing class when inherited
--FILE--
<?php
trait ClassIdentityTrait
{
public function magicClass(): string
{
return __CLASS__;
}
public function selfClass(): string
{
return self::class;
}
}
class Base
{
use ClassIdentityTrait;
}
class Child extends Base
{
}
function main(): void
{
$object = new Child();
var_dump($object->magicClass());
var_dump($object->selfClass());
}
?>
--EXPECT--
string(4) "Base"
string(4) "Base"
Loading…
Cancel
Save