3v4l.org

run code in 300+ PHP versions simultaneously
<?php $obj = new stdClass(); $obj->name = 'Fred'; $obj->job = new stdClass(); $obj->job->position = 'Janitor'; $obj->job->years = 4; print_r($obj); echo 'Years in current job: '.string($obj, 'job->years').PHP_EOL; function string($obj, $path_str) { $val = null; $path = preg_split('/->/', $path_str); $node = $obj; while (($prop = array_shift($path)) !== null) { if (!property_exists($node, $prop)) { $val = null; break; } echo 'Has property: '.$prop; echo $node->$prop; $node = $node->$prop; $val = $node->$prop; } return $val; }
Output for git.master, git.master_jit, rfc.property-hooks
stdClass Object ( [name] => Fred [job] => stdClass Object ( [position] => Janitor [years] => 4 ) ) Has property: job Fatal error: Uncaught Error: Object of class stdClass could not be converted to string in /in/rmCB4:25 Stack trace: #0 /in/rmCB4(10): string(Object(stdClass), 'job->years') #1 {main} thrown in /in/rmCB4 on line 25
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:
44.86 ms | 401 KiB | 8 Q