/** * Makes the object unmodifiable. * @return void */ public function freeze() { parent::freeze(); foreach ($this->getArrayCopy() as $val) { if ($val instanceof self) { $val->freeze(); } } }
} // List::__construct() $arr = array('a' => $jack, 'b' => $mary, 'c' => $foo); try { echo "Construct from array\n"; $hashtable2 = new Hashtable($arr, 'Person'); } catch (Exception $e) { echo get_class($e), ': ', $e->getMessage(), "\n\n"; } echo "Construct from array II.\n"; $hashtable2 = new Hashtable($arr); Debug::dump($hashtable2); // readonly collection echo "Construct as readonly\n"; $hashtable2 = new Hashtable($hashtable); $hashtable2->freeze(); Debug::dump($hashtable2->isFrozen()); try { echo "Adding Jack using []\n"; $hashtable2['new'] = $jack; } catch (Exception $e) { echo get_class($e), ': ', $e->getMessage(), "\n\n"; } try { echo "Adding Jack using add\n"; $hashtable2->add('new', $jack); } catch (Exception $e) { echo get_class($e), ': ', $e->getMessage(), "\n\n"; } try { echo "Removing using unset\n";