3v4l.org

run code in 300+ PHP versions simultaneously
<?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 function 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 git.master, git.master_jit, rfc.property-hooks
NULL int(25)

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:
40.04 ms | 401 KiB | 8 Q