3v4l.org

run code in 300+ PHP versions simultaneously
<?php class container { protected $storage=array(); public function add(test1 $obj) { if(!isset($this->storage[spl_object_hash($obj)])) { $this->storage[spl_object_hash($obj)]=$obj; } } } class test1 { public function __construct($s) { } } $o=new container(); $o->add(new test1("lalala")); // will be added $o->add(new test1("lololo")); // not added - NOT as expected $t=new test("lalala"); $o=new container(); $o->add($t); // will be added $o->add($t); // not added - as expected var_dump($o);

preferences:
37.88 ms | 402 KiB | 5 Q