3v4l.org

run code in 300+ PHP versions simultaneously
<?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->alias(); }
Output for 5.3.0 - 5.3.29, 5.4.0 - 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.10, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Calling virtual method alias... That's an alias for actualMethod... Inside the actual method
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_STRING in /in/m596d on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING in /in/m596d on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/m596d on line 2
Process exited with code 255.

preferences:
229.52 ms | 401 KiB | 313 Q