3v4l.org

run code in 300+ PHP versions simultaneously
<?php class test { protected $_a = 6; function __get($key) { echo "__get({$key})\n"; if($key == 'stuff') { return $this->stuff(); } else if($key == 'a') { return $this->_a + 2; } } function stuff() { echo "stuff()\n"; return array('random' => 'key', 'using_getter' => 10 * $this->a); } function hey() { return $this->a; } } class me extends test { function __get( $name){ $val = parent::__get($name); if ($name === 'a' ) { $val = parent::a - 5; } return $val; } } $test = new test(); print 'this should be 60: '.$test->stuff['using_getter'].PHP_EOL; print 'this should be 6: '.$test->a.PHP_EOL; print $test->hey(); $me = new me(); print $me->a;
Output for git.master, git.master_jit, rfc.property-hooks
__get(stuff) stuff() __get(a) this should be 60: 80 __get(a) this should be 6: 8 __get(a) 8__get(a) Fatal error: Uncaught Error: Undefined constant test::a in /in/uf1Mq:32 Stack trace: #0 /in/uf1Mq(47): me->__get('a') #1 {main} thrown in /in/uf1Mq on line 32
Process exited with code 255.

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