3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public $elements = array(); public function __construct() { $stdObj = new stdClass; $stdObj->name = 'foo1'; $stdObj->active = false; $this->elements[] = $stdObj; } public function getElementByName($name) { foreach($this->elements as $elm) { if ($elm->name == $name) { return $elm; } } } public function test( ){ return $this->elements; } } $myFoo = new Foo(); $myFoo->getElementByName('foo1')->active = true; var_dump($myFoo->test());

preferences:
42.47 ms | 402 KiB | 5 Q