<?php
trait TraitWithProperties
{
private $a = 'foo';
protected $b = 'bar';
public $c = 'baz';
private static $as = self::class;
protected static $bs = __TRAIT__;
public static $cs = __CLASS__;
}
class SimpleClassWithTrait
{
use TraitWithProperties;
}
$refClass = new ReflectionClass('SimpleClassWithTrait');
var_dump($refClass->getStaticProperties());
- Output for 5.6.17 - 5.6.40, 7.0.1 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- array(3) {
["as"]=>
string(20) "SimpleClassWithTrait"
["bs"]=>
string(19) "TraitWithProperties"
["cs"]=>
string(20) "SimpleClassWithTrait"
}
- Output for 5.5.0 - 5.5.20, 5.6.0 - 5.6.4, 7.0.0
- array(3) {
["as"]=>
string(19) "TraitWithProperties"
["bs"]=>
string(19) "TraitWithProperties"
["cs"]=>
string(20) "SimpleClassWithTrait"
}
- Output for 5.5.21 - 5.5.38, 5.6.5 - 5.6.16
- Fatal error: Invalid binding type in /in/0n4mP on line 12
Process exited with code 139.
preferences:
271.64 ms | 402 KiB | 330 Q