3v4l.org

run code in 300+ PHP versions simultaneously
<?php class AnonObject{ private $properties = array(); private $methods = array(); public function __get($property){ return array_key_exists($property, $this->properties)?$this->properties[$property]:null; } public function __set($property, $value){ if (!is_string($value) && is_callable($value)){ if ($value instanceof \Closure){ // bind the closure to this object's instance and static context $this->methods[$property] = $value->bindTo($this,get_class($this)); } else { // invokable objects $this->methods[$property] = $value; } } else { $this->properties[$property] = $value; } } public function __call($method, $args){ if (array_key_exists($method, $this->methods)){ call_user_func_array($this->methods[$method], $args); } else { throw new RuntimeException("Method ".$method." does not exist on object"); } } } $a = new AnonObject(); $a->prop1 = "Property 1"; $a->method = function (){ echo $this->prop1; };
Output for git.master, git.master_jit, rfc.property-hooks

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
60.27 ms | 401 KiB | 8 Q