3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Foo { public static $has_many = "Post"; public function has_many($a){ return 'hola'; } function get_relationship($model) { $class = new ReflectionClass($this); $staticProperties = $class->getStaticProperties(); foreach($staticProperties as $propertyName => $value) { if(preg_match('/^(has_many|age)$/', $propertyName) && $value == $model) { return $this->{$propertyName}($model); } } } function __get($name) { if(substr($name, -strlen('_set')) === '_set') { $model = ucwords(substr($name, 4)); return $this->get_relationship($model); } } } echo substr($name, -strlen('_set')); $foo = new Foo; echo $foo->post_set; ?>
Output for 5.0.4 - 5.6.25, hhvm-3.10.0, 7.0.0 - 7.1.0
Notice: Undefined variable: name in /in/aIahd on line 36
Output for hhvm-3.12.0
Notice: Undefined variable: name in /in/aIahd on line 36 Warning: substr() expects parameter 1 to be string, null given in /in/aIahd on line 36
Output for 5.0.0 - 5.0.3
Notice: Undefined variable: name in /in/aIahd on line 36
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/aIahd on line 4
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/aIahd on line 4
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/aIahd on line 4
Process exited with code 255.