} if ($success) { echo "Success! ({$hash}, {$hash2})\n"; } else { echo "Failure..."; } class testClass { public $publicProp; } $obj = new testClass(); $identity = null; echo "Add Reference -> \n"; try { $obj->publicProp = 2; $identity = $testSet->addReference($obj); $obj->publicProp = 3; echo "\nSet Internals --\n\n"; var_dump($testSet->getArray()); echo "\n"; } catch (\Exception $e) { echo "EXCEPTION CAUGHT\n"; } echo "Retrieve Reference -> "; unset($obj); try { $obj = $testSet->retrieveReference($identity); $obj->publicProp = 5; echo "\n\nSet Internals -- \n\n"; var_dump($testSet->getArray()); echo "\n";
/** * Add a value to the set as a reference * * Runs the value by the restrictions, only triggering if set is strict * otherwise doing nothing and exiting the function * * @param mixed $value Value to add to the set, must be of allowed type * * @return string|false The datum identifier, false otherwise * * @throws Exception\InvalidArgumentException if 'strict' option is set * and type is not in Restrictions * */ public function addReference(&$value) { try { $valid = Restrictions::checkElements(array($value), $this->restrictions, $this->conf->strict); } catch (Exception\InvalidArgumentException $e) { if ($this->conf->strict) { throw new Exception\InvalidArgumentException('RestrictedSet->addReference: Restricted Value'); } else { return false; } } // Passes restrictions, but safety check if ($valid) { return parent::addReference($value); } }