3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class DependencyContainer { /** * * @var array */ private $dependencies; /** * * @param string $key * @param string $value */ public function __set($key, $value) { $this->setDependency($key, $value); } /** * * @param string $name * @return mixed */ public function __get($name) { return $this->getDependency($name); } /** * * @param string $dependency_name * @param mixed $implementation * @throws InvalidArgumentException */ public function setDependency($dependency_name, $implementation) { if(!is_string($dependency_name)) throw new InvalidArgumentException( '$dependency_name must be a string! '.gettype($dependency_name).' given!' ); $this->dependencies[$dependency_name] = $implementation; } /** * * @param string $dependency_name * @throws InvalidArgumentException Wird geworfen wenn der erste Parameter kein String ist. * @throws OutOfRangeException Wird geworfen wenn für die Dependency keine Implementierung gesetzt wurde. * @return string */ public function getDependency($dependency_name) { if(!is_string($dependency_name)) throw new InvalidArgumentException( '$dependency_name must be a string! '.gettype($dependency_name).' given!' ); if(!isset($this->dependencies[$dependency_name])) throw new OutOfRangeException('No dependency set for '.$dependency_name.'!'); if(is_callable($this->dependencies[$dependency_name])) return $this->dependencies[$dependency_name]($this); else return $this->dependencies[$dependency_name]; } public function getSingelton($lambda) { return function($container) use ($lambda) { static $object; if(is_null($object)) $object = $lambda($container); return $object; }; } } ?>
Output for 5.3.0 - 7.1.0
Output for 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/v7fME on line 72
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/v7fME on line 72
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/v7fME on line 9
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/v7fME on line 9
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/v7fME on line 9
Process exited with code 255.