mirror of
https://github.com/php/php-src.git
synced 2024-10-16 22:12:33 +00:00
0158804a15
# __TRAIT__ behaves like __CLASS__ more or less but is constraint to traits. # Since traits are not types, there are not many valid use cases, and trying # to use __TRAIT__ to make traits more like classes is discouraged.
37 lines
515 B
PHP
37 lines
515 B
PHP
--TEST--
|
|
__TRAIT__: Basics, a constant denoiting the trait of definition.
|
|
--FILE--
|
|
<?php
|
|
|
|
trait TestTrait {
|
|
public static function test() {
|
|
return __TRAIT__;
|
|
}
|
|
}
|
|
|
|
class Direct {
|
|
use TestTrait;
|
|
}
|
|
|
|
class IndirectInheritance extends Direct {
|
|
|
|
}
|
|
|
|
trait TestTraitIndirect {
|
|
use TestTrait;
|
|
}
|
|
|
|
class Indirect {
|
|
use TestTraitIndirect;
|
|
}
|
|
|
|
echo Direct::test()."\n";
|
|
echo IndirectInheritance::test()."\n";
|
|
echo Indirect::test()."\n";
|
|
|
|
?>
|
|
--EXPECT--
|
|
TestTrait
|
|
TestTrait
|
|
TestTrait
|