3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Test { protected $myName; public function __set($key, $value) { if (property_exists($this, $key)) $this->$key = $value; return null; } public function __get($key) { return property_exists($this, $key) ? $this->$key : null; } public function __call($name, $arguments) { $matches = array(); $pattern = '/^set([A-Za-z0-9]+)/'; if (preg_match($pattern, $name, $matches)) { return $this->__set($this->getProp($matches[1]), $arguments[0]); } $pattern = '/^get([A-Za-z0-9]+)/'; if (preg_match($pattern, $name, $matches)) { return $this->__get($this->getProp($matches[1])); } } protected getProp($matches) { return strtolower($matches[0]) . substr($matches, 1, strlen($matches)-1); } } $test = new Test; var_dump($test->getMyName()); $test->setMyName(25); var_dump($test->getMyName());
Output for 5.4.13
Parse error: syntax error, unexpected 'getProp' (T_STRING), expecting variable (T_VARIABLE) in /in/j4L9E on line 32
Process exited with code 255.
Output for 5.4.0 - 5.4.12
Parse error: syntax error, unexpected 'getProp' (T_STRING), expecting variable (T_VARIABLE) in NIOkC on line 32
Process exited with code 255.
Output for 5.3.23
Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE in /in/j4L9E on line 32
Process exited with code 255.
Output for 5.3.0 - 5.3.22
Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE in NIOkC on line 32
Process exited with code 255.