3v4l.org

run code in 300+ PHP versions simultaneously
<?php class demo { public function MethodA() { return 'method A from class'; } public function MethodC() { return 'method C from class'; } public function MethodE() { return 'method E from class'; } use tGeneric; } trait tGeneric { public function MethodA() { return 'method A from trait'; } public function MethodB() { return 'method B from trait'; } public function MethodD() { return 'method D from trait'; } public function MethodE() { return 'method E from trait'; } } /** * Given a class name, retrieves the corresponding class' methods that override * trait methods. * * @param string $class_name * @return \ReflectionMethod[] * @throws \ReflectionException */ function getMethodsOverriddenFromTraits(string $class_name): array { $class = new \ReflectionClass($class_name); // Retrieve trait methods $trait_methods = []; foreach ($class->getTraits() as $trait) { foreach ($trait->getMethods() as $trait_method) { $trait_methods[$trait_method->getName()] = $trait_method; } } // Compute class methods that override them $methods_overridden = []; foreach ($class->getMethods() as $class_method) { if (array_key_exists($class_method->getName(), $trait_methods)) { $trait_method = $trait_methods[$class_method->getName()]; if ($class_method->getFileName() !== $trait_method->getFileName() || $class_method->getStartLine() !== $trait_method->getStartLine()) { $methods_overridden[] = $class_method->getName(); } } } return $methods_overridden; } print_r(getMethodsOverriddenFromTraits('demo'));
Output for 7.0.33, 7.1.25 - 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.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14, 8.5.0
Array ( [0] => MethodA [1] => MethodE )
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 5.6.38
Parse error: syntax error, unexpected ':', expecting '{' in /in/EcFIC on line 54
Process exited with code 255.

preferences:
189.7 ms | 408 KiB | 5 Q