3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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' )); }
based on n6Nct
Output for 5.4.1 - 7.2.0
Notice: Undefined variable: args in /in/5g4aU on line 9
Process exited with code 137.
Output for 5.3.12 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/5g4aU on line 19
Process exited with code 255.