3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Allows value objects to expose their properties while maintaining immutability. * * Define your properties in the docblock for your class with {@code @property}. */ class Value { private $a; public function __construct($a) { $this->a = $a; } public function __get($aProperty) { if (property_exists($this, $aProperty)) { return $this->{$aProperty}; } $this->triggerError("Undefined property: %s::$%s", $aProperty); } public function __set($aProperty, $aValue) { if (property_exists($this, $aProperty)) { $this->triggerError("Cannot access private property %s::$%s", $aProperty); } $this->triggerError("Undefined property: %s::$%s", $aProperty); } private function triggerError($message, $aProperty) { $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); throw new ErrorException(sprintf($message, __CLASS__, $aProperty), 0, E_USER_NOTICE, $backtrace[2]['file'], $backtrace[2]['line']); } } $v = new Value(1); var_dump($v->a); var_dump($v->b); $v->a = 3; $v->b = 4;
Output for git.master, git.master_jit
int(1) Warning: Undefined array key 2 in /in/TIQNE on line 32 Warning: Trying to access array offset on value of type null in /in/TIQNE on line 32 Warning: Undefined array key 2 in /in/TIQNE on line 32 Warning: Trying to access array offset on value of type null in /in/TIQNE on line 32 Fatal error: Uncaught ErrorException: Undefined property: Value::$b in /in/TIQNE:32 Stack trace: #0 /in/TIQNE(20): Value->triggerError('Undefined prope...', 'b') #1 /in/TIQNE(39): Value->__get('b') #2 {main} thrown in /in/TIQNE on line 32
Process exited with code 255.
Output for rfc.property-hooks
int(1) Warning: Undefined array key 2 in /in/TIQNE on line 32 Warning: Trying to access array offset on null in /in/TIQNE on line 32 Warning: Undefined array key 2 in /in/TIQNE on line 32 Warning: Trying to access array offset on null in /in/TIQNE on line 32 Fatal error: Uncaught ErrorException: Undefined property: Value::$b in /in/TIQNE:32 Stack trace: #0 /in/TIQNE(20): Value->triggerError('Undefined prope...', 'b') #1 /in/TIQNE(39): Value->__get('b') #2 {main} thrown in /in/TIQNE 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:
38.43 ms | 408 KiB | 5 Q