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); string($obj, 'job->years'); function string($object, $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; } $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 ) ) Warning: Undefined variable $obj in /in/dQ7E3 on line 17 Fatal error: Uncaught TypeError: property_exists(): Argument #1 ($object_or_class) must be of type object|string, null given in /in/dQ7E3:19 Stack trace: #0 /in/dQ7E3(19): property_exists(NULL, 'job') #1 /in/dQ7E3(10): string(Object(stdClass), 'job->years') #2 {main} thrown in /in/dQ7E3 on line 19
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:
43.79 ms | 402 KiB | 8 Q