Created
March 18, 2022 09:50
-
-
Save amcsi/bf2f44bb6d79175a85943f3bcd30a710 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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