Skip to content

Instantly share code, notes, and snippets.

@amcsi
Created March 18, 2022 09:50
Show Gist options
  • Save amcsi/bf2f44bb6d79175a85943f3bcd30a710 to your computer and use it in GitHub Desktop.
Save amcsi/bf2f44bb6d79175a85943f3bcd30a710 to your computer and use it in GitHub Desktop.
<?php
class ObjectStorage {
public $pairs = [];
public function add(object $objectKey, $value): void
{
$this->pairs[] = [$objectKey, $value];
}
public function has(object $object): bool
{
return (bool) $this->get($object);
}
public function get(object $object)
{
foreach ($this->pairs as $pair) {
if ($pair[0] === $object) {
return $object;
}
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment