<?php
class Test {}
function addToStorage(\SplObjectStorage $storage, Test $test) {
if (!$storage->contains($test)) {
$storage->attach($test);
}
}
$storage = new \SplObjectStorage();
$test1 = new Test();
$test2 = new Test();
addToStorage($storage, $test1);
addToStorage($storage, $test2);
echo $storage->count();