Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Foo {
- public function __call($methodName, $parameters) {
- if (strpos($methodName, 'getValid') !== false) {
- $propName = lcfirst(substr($methodName, 8));
- if (property_exists($this, $propName)) {
- if (property_exists($this, $methodName)) {
- $anoMeth = $this->$methodName;
- return $anoMeth($this);
- } else {
- return htmlspecialchars($this->$propName);
- }
- } else {
- return null;
- }
- }
- }
- }
- $foo = new Foo();
- $foo->name = 'blubber';
- $foo->getValidName = function($obj) {
- return htmlspecialchars($obj->name);
- };
- $foo->number = 13;
- echo $foo->getValidNumber() . '<br />';
- echo $foo->getValidName();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement