- 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 behaviorpull/47/head
parent
ca41af9bb5
commit
8d4801ebd2
1 changed files with 36 additions and 0 deletions
@ -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…
Reference in new issue