3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class DIContainer { private var $properties = array(); public function __set($propertyName, $value) { $this->properties[$propertyName] = $value; } public function __get($propertyName) { return is_callable($this->properties[$propertyName]) ? $this->properties[$propertyName]($this) : $this->properties[$propertyName]; } } class DatabaseConnection { public var $hostname; public var $username; public var $password; public function __construct($hostname, $username, $password) { $this->hostname = $hostname; $this->username = $username; $this->password = $password; } } $di = new DIContainer(); $di->databaseHostname = 'dbmaster'; $di->databaseUsername = 'user'; $di->databasePassword = '123456'; $di->databaseConnectionClass = 'DatabaseConnection'; $di->databaseConnection = function ($di) { $className = $di->databaseConnectionClass; return new $className($di->databaseHostname, $di->databaseUsername, $di->databasePassword); }; $db = $di->databaseConnection; print_r($db);
Output for 5.4.0 - 5.4.24
Parse error: syntax error, unexpected 'var' (T_VAR), expecting variable (T_VARIABLE) in /in/OHGQJ on line 4
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected T_VAR, expecting T_VARIABLE in /in/OHGQJ on line 4
Process exited with code 255.