Portál AbcLinuxu, 13. května 2025 21:51
class Registry { private $registry = array(); public function set($key, $value) { if (isset($this->registry[$key])) { throw new Exception("There is already an entry for key " . $key); } $this->registry[$key] = $value; } public function get($key) { if (!isset($this->registry[$key])) { throw new Exception("There is no entry for key " . $key); } return $this->registry[$key]; } }
Řešení dotazu:
get()
na __get()
a set()
na __set()
.
Registry však jsou trochu mimo OOP, ale zdá se, že ti to nebude vadit.
$register = new stdClass();Je to skoro totéž.
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.