3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait x { public function bar() { echo 'Trait x bar()'; } public function foo() { echo 'Trait x foo()'; } } class z { use x; public function foo() { echo 'Class foo()'; } } function getClassAndTraitMethods(ReflectionClass $class) { $traitMethods = []; foreach($class->getTraits() as $trait) { foreach($trait->getMethods() as $method) { $traitMethods[] = $method; } } $traitRefs = []; foreach($traitMethods as $traitMethod) { $traitRefs[spl_object_hash($traitMethod)]=$traitMethod->name; } $classMethods = []; $classRefs = []; foreach($class->getMethods() as $classMethod) { $classMethods[]=$classMethod; $classRefs[spl_object_hash($classMethod)] = $classMethod->name; } return ['traitRefs'=>$traitRefs,'classRefs'=>$classRefs]; } $obj = new z; $ref = new ReflectionClass($obj); extract(getClassAndTraitMethods($ref)); $traitOnlyHashes = array_diff( array_keys($traitRefs), array_keys($classRefs) ); $traitOnlyMethods = array_intersect_key($traitRefs, array_flip($traitOnlyHashes)); print_r($traitRefs); print_r($classRefs); print_r($traitOnlyMethods);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [00000000000000040000000000000000] => bar [00000000000000050000000000000000] => foo ) Array ( [00000000000000060000000000000000] => foo [00000000000000070000000000000000] => bar ) Array ( [00000000000000040000000000000000] => bar [00000000000000050000000000000000] => foo )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
30.67 ms | 406 KiB | 5 Q