3v4l.org

run code in 300+ PHP versions simultaneously
<?php function instantiable($className) { if (! $className) { return true; } $reflection = new ReflectionClass($className); if ($reflection->isAbstract()) { return false; } $hasFinalConstruct = false; if ($reflection->hasMethod('__construct')) { $hasFinalConstruct = $reflection->getMethod('__construct')->isFinal(); } $parentClass = $reflection->getParentClass(); return instantiable($parentClass ? $parentClass->getName() : null) && ! ($reflection->isInternal() && $hasFinalConstruct); }; $negate = function ($function) { return function (...$args) use ($function) { return ! $function(...$args); }; }; var_dump([ 'instantiable' => array_filter(get_declared_classes(), 'instantiable')) 'not_instantiable' => array_filter(get_declared_classes(), $negate('instantiable')), ]);
Output for 5.4.0 - 5.4.31
Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in /in/j2YtD on line 27
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected '.', expecting '&' or T_VARIABLE in /in/j2YtD on line 27
Process exited with code 255.

preferences:
186.44 ms | 1386 KiB | 68 Q