3v4l.org

run code in 200+ PHP versions simultaneously
<?php class b{ public $o; public function __construct(){ $this->o = (object)array('id'=>12); } } class foo { private $b; public function __construct(){ $this->b = new b(); } public function bar(){ return $this->b; } } $f = new foo(); var_dump( $f->bar()->o->id );
based on uc9VI
Output for 7.1.25 - 7.3.3
int(12)