Skip to content

Instantly share code, notes, and snippets.

@anytizer
Created October 22, 2013 07:38
Show Gist options
  • Save anytizer/7096589 to your computer and use it in GitHub Desktop.
Save anytizer/7096589 to your computer and use it in GitHub Desktop.
Fixed parameters
<?php
/**
* Controlled way of handling parameter names.
* The script cannot add or read new parameters dynamically.
*/
abstract class FixedParameters
{
/**
* Does not allow the script to modify set of parameters later on.
*/
public function __set($key='', $value='')
{
if(property_exists($this, $key))
{
$this->$key = $value;
}
else
{
throw new Exception('Cannot set value of an undefined key ({$key}).');
}
}
/**
* Does not allow to read the undefined parameters
*/
public function __get($key='')
{
if(!property_exists($this, $key))
{
throw new Exception("Cannot read undefined key ({$key}).");
}
return $this->$key;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment