3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php namespace My\Example\Model { abstract class Super { private $aliases; protected function __construct(array $aliases) { $this->aliases = $aliases; } public function __call($name, $arguments) { echo "Calling virtual method $name...\n"; /* if $name is an alias, replace it */ if (isset($this->aliases[$name])) { $name = $this->aliases[$name]; echo "That's an alias for $name...\n"; } /* throw an exception if the method is undefined */ if (!method_exists($this, $name)) { throw new \Exception("The specified method or method alias is undefined in the current context"); } /* finally, call the method by its actual name */ return $this->$name($arguments); } } } namespace My\Example\Model { class Sub extends Super { public function __construct() { parent::__construct(array( "alias" => "actualMethod" )); } public function actualMethod() { echo "Inside the actual method\n"; } } } namespace My\Example { $sub = new Model\Sub; $sub->aliassss(); }
Output for 7.0.0 - 7.1.0
Calling virtual method aliassss... Fatal error: Uncaught Exception: The specified method or method alias is undefined in the current context in /in/Trqpj:24 Stack trace: #0 /in/Trqpj(54): My\Example\Model\Super->__call('aliassss', Array) #1 {main} thrown in /in/Trqpj on line 24
Process exited with code 255.
Output for 5.3.3 - 5.6.28
Calling virtual method aliassss... Fatal error: Uncaught exception 'Exception' with message 'The specified method or method alias is undefined in the current context' in /in/Trqpj:24 Stack trace: #0 /in/Trqpj(54): My\Example\Model\Super->__call('aliassss', Array) #1 /in/Trqpj(54): My\Example\Model\Sub->aliassss() #2 {main} thrown in /in/Trqpj on line 24
Process exited with code 255.
Output for 5.3.0 - 5.3.2
Calling virtual method aliassss... Fatal error: Uncaught exception 'Exception' with message 'The specified method or method alias is undefined in the current context' in /in/Trqpj:24 Stack trace: #0 [internal function]: My\Example\Model\Super->__call('aliassss', Array) #1 /in/Trqpj(54): My\Example\Model\Sub->aliassss() #2 {main} thrown in /in/Trqpj on line 24
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_STRING in /in/Trqpj on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING in /in/Trqpj on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/Trqpj on line 2
Process exited with code 255.