- var_dump: documentation ( source)
- spl_object_hash: documentation ( source)
<?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);