3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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 var_dump(spl_object_hash(new test1('1')) === spl_object_hash(new test1('2')) === spl_object_hash(new test1('2')) === spl_object_hash(new test1('2'))); var_dump(spl_object_hash(new test1('2'))); $t=new test1("lalala"); $o=new container(); $o->add($t); // will be added $o->add($t); // not added - as expected var_dump($o);
Output for 5.4.0 - 5.5.4
Parse error: syntax error, unexpected '===' (T_IS_IDENTICAL) in /in/BeAcC on line 19
Process exited with code 255.
Output for 5.3.0 - 5.3.27
Parse error: syntax error, unexpected T_IS_IDENTICAL in /in/BeAcC on line 19
Process exited with code 255.