- var_dump: documentation ( source)
<?php
class User{
public $id;
function __construct($id)
{
$this->id = $id;
}
}
class UserStorage extends SPLObjectStorage{
public function getHash($obj){
return $obj->id;
}
}
$us = new UserStorage();
$user1 = new User(1);
$user2 = new User(2);
$us->attach($user1);
$us->attach($user2);
$me = new User(2);
// the following would normally fail since they are two separate objects
// but it works now with our extended getHash()
var_dump($us->contains($me));