<?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);
Fatal error: Uncaught Error: Class "test" not found in /in/rKrng:19
Stack trace:
#0 {main}
thrown in /in/rKrng on line 19
Process exited with code 255.
Fatal error: Uncaught Error: Class 'test' not found in /in/rKrng:19
Stack trace:
#0 {main}
thrown in /in/rKrng on line 19
Process exited with code 255.
Fatal error: Class 'test' not found in /in/BHaNW on line 19
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
Fatal error: Call to undefined function spl_object_hash() in /in/BHaNW on line 5
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/BHaNW on line 3
Process exited with code 255.
Output for 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/BHaNW on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/BHaNW on line 3
Process exited with code 255.
Output for 4.3.0
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/rKrng on line 3
Process exited with code 255.