Estive passando os seguintes erros por optar usar SplObjectStorage
:
uncaught Error: Call to undefined method SplObjectStorage::add()
Uncaught Error: Call to undefined method SplObjectStorage::remove()
Para soluciona-los precisei considerar outros metodos:
- attach() no lugar de add()
- detach() no lugar de remove()
Ficou assim:
$chatComponent = new class implements MessageComponentInterface
{
private SplObjectStorage $connections;
public function __construct()
{
echo "Nova conexão aceita " . PHP_EOL;
$this->connections = new SplObjectStorage();
}
public function onOpen(ConnectionInterface $conn)
{
echo "Conexão encerrada " . PHP_EOL;
$this->connections->attach($conn);
}
public function onClose(ConnectionInterface $conn)
{
$this->connections->detach($conn);
}
...
}