3v4l.org

run code in 300+ PHP versions simultaneously
<?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));

preferences:
39.37 ms | 402 KiB | 5 Q