3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php //! PHP magic wrapper class Magic0 implements ArrayAccess { var $properties; //protected would be better function exists($key) { return isset($this->properties[$key]); } function set($key,$val) { return $this->properties[$key]=$val; } function get($key) { return isset($this->properties[$key])?$this->properties[$key]:NULL; } function clear($key) { unset($this->properties[$key]); } function __isset($key) { return $this->offsetexists($key); } function __set($key,$val) { return $this->offsetset($key,$val); } function offsetexists($key) { return exists($key); } function offsetset($key,$val) { return $this->set($key,$val); } function offsetget($key) { return $this->get($key); } function offsetunset($key) { $this->clear($key); } function __get($key) { return $this->offsetget($key); } function __unset($key) { $this->offsetunset($key); } } //in every case, it will create entry in internal array $sample=new Magic0(); $sample->a=11; $sample->b="Muse"; $sample['c']=13; //we can get them through array index as well echo $sample['a'] ."\n"; echo $sample['b'] ."\n"; echo $sample->c ."\n";
Output for 5.1.3 - 5.6.28, hhvm-3.10.0 - 3.13.2, 7.0.0 - 7.1.0
11 Muse 13
Output for 5.0.0 - 5.1.2
Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/PCn1n on line 5 11 Muse 13
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/PCn1n on line 3
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 '{' in /in/PCn1n on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/PCn1n on line 3
Process exited with code 255.