3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function get_class_name($class) { if (is_object($class)) { return get_class_name(get_class($class)); } else if (is_string($class)) { if (strpos('\\', $class) !== false) { return substr(strrchr($class, '\\'), 1); } return $class; } return false; } abstract class Visitor { public final function __call(string $method, array $args) { if ($method === 'visit') { $method .= get_class_name(static::class); die($method); if (method_exists($this, $method)) { return call_user_func_array([$this, $method], $args); } } throw new Exception('Unknown method ' . $method); } } interface Visitable { public function accept(Visitor $v); } class FooVisitor extends Visitor { public function visitFoo(Foo $foo) { print 'visit Foo' . PHP_EOL; } } class Foo implements Visitable { public function accept(Visitor $v) { $v->visit($this); } } $fv = new FooVisitor(); $f = new Foo(); $f->accept($fv);
based on n2iJ0
Output for 7.0.0 - 7.3.0beta1
visitFooVisitor
Output for 5.5.0 - 5.6.28
Catchable fatal error: Argument 1 passed to Visitor::__call() must be an instance of string, string given in /in/NQdv0 on line 20
Process exited with code 255.