Skip to content

Instantly share code, notes, and snippets.

@masakielastic
Created March 16, 2009 01:02
Show Gist options
  • Save masakielastic/79616 to your computer and use it in GitHub Desktop.
Save masakielastic/79616 to your computer and use it in GitHub Desktop.
dynamic accessor
<?php
class BaseClass
{
public function __call($name, $arguments)
{
$prefix = substr($name, 0, 3);
$property = substr(strtolower($name), 3);
if ($prefix == 'set')
{
$this->$property = $arguments[0];
}
elseif ($prefix == 'get')
{
return $this->$property;
}
}
}
$obj = new BaseClass();
$obj->setTest('Help');
echo $obj->getTest();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment