3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace { function callable_equals(){ $strict = false; $callables = func_get_args(); if(is_bool($args[count($callables) - 1])){ $strict = $args[count($callables) - 1]; $callables = array_splice($callables, 0, -1); } $normalizeCallable = function(callable $callable){ if(is_string($callable)){ $callable = strtolower($callable); $pieces = explode("::", $callable); if(count($pieces) == 2){ return [$pieces[0], $pieces[1]]; } return $callable; } if(is_string($callable[0])){ $callable[0] = strtolower($callable[0]); } $callable[1] = strtolower($callable[1]); return $callable; }; if(count($callables) < 2){ trigger_error("callable_equals() requires at least 2 callables for comparison.", E_USER_WARNING); return null; } foreach($callables as $i => $callable){ if(!is_callable($callable)){ trigger_error("Argument " . ($i + 1) . " is not a callable.", E_USER_WARNING); return null; }else{ $callables[$i] = $normalizeCallable($callable); } } $callable = array_shift($callables); while($callables){ if($callable !== $callables[0]) return false; } return true; } class Foo{static function bar(){}} } namespace A\b\C\d { class Foo{static function bar(){}} } namespace { var_dump(callable_equals( ['Foo', 'bar'], 'foo::BAR' )); var_dump(callable_equals( ['A\\b\\C\\d\\Foo', 'bAr'], 'a\\B\\c\\D\\FoO::bar' )); }
Output for 8.3.0 - 8.3.4, 8.3.6
Warning: Undefined variable $args in /in/5g4aU on line 9 Warning: Trying to access array offset on null in /in/5g4aU on line 9
Process exited with code 137.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Warning: Undefined variable $args in /in/5g4aU on line 9 Warning: Trying to access array offset on null in /in/5g4aU on line 9
Process exited with code 137.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
Warning: Undefined variable $args in /in/5g4aU on line 9 Warning: Trying to access array offset on value of type null in /in/5g4aU on line 9
Process exited with code 137.
Output for 7.4.0 - 7.4.33
Notice: Undefined variable: args in /in/5g4aU on line 9 Notice: Trying to access array offset on value of type null in /in/5g4aU on line 9
Process exited with code 137.
Output for 7.3.32 - 7.3.33

Process exited with code 137.
Output for 5.4.1 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.31
Notice: Undefined variable: args in /in/5g4aU on line 9
Process exited with code 137.

preferences:
176.72 ms | 403 KiB | 229 Q