Created
March 16, 2009 01:02
-
-
Save masakielastic/79616 to your computer and use it in GitHub Desktop.
dynamic accessor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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