3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait x { public function foo() { echo 'Trait x foo()'; } public function bar() { echo 'Trait x bar()'; } } class z { use x; public function foo() { echo 'Class foo()'; } } function getTraitMethodsRefs(ReflectionClass $class) { $traitMethods = call_user_func_array('array_merge', array_map(function(ReflectionClass $ref) { return $ref->getMethods(); }, $class->getTraits())); $traitMethods = call_user_func_array('array_merge', array_map(function (ReflectionMethod $method) { return [spl_object_hash($method) => $method->getName()]; }, $traitMethods)); return $traitMethods; } function getClassMethodsRefs(ReflectionClass $class) { return call_user_func_array('array_merge', array_map(function (ReflectionMethod $method) { return [spl_object_hash($method) => $method->getName()]; }, $class->getMethods())); } $obj = new z; $ref = new ReflectionClass($obj); $traitRefs = getTraitMethodsRefs($ref); $classRefs = getClassMethodsRefs($ref); $traitOnlyHashes = array_diff( array_keys($traitRefs), array_keys($classRefs) ); $traitOnlyMethods = array_intersect_key($traitRefs, array_flip($traitOnlyHashes)); var_dump( $traitRefs, $classRefs, $traitOnlyMethods );
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught ArgumentCountError: array_merge() does not accept unknown named parameters in /in/mN7In:31 Stack trace: #0 /in/mN7In(31): array_merge(x: Array) #1 /in/mN7In(49): getTraitMethodsRefs(Object(ReflectionClass)) #2 {main} thrown in /in/mN7In on line 31
Process exited with code 255.

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:
65.02 ms | 401 KiB | 8 Q