Advertisement
Guest User

Untitled

a guest
May 19th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. <?php
  2. class Foo {
  3.     public function __call($methodName, $parameters) {
  4.         if (strpos($methodName, 'getValid') !== false) {
  5.             $propName = lcfirst(substr($methodName, 8));
  6.             if (property_exists($this, $propName)) {
  7.                 if (property_exists($this, $methodName)) {
  8.                     $anoMeth = $this->$methodName;
  9.                     return $anoMeth($this);
  10.                 } else {
  11.                     return htmlspecialchars($this->$propName);
  12.                 }
  13.             } else {
  14.                 return null;
  15.             }
  16.         }
  17.     }
  18. }
  19.  
  20. $foo = new Foo();
  21.  
  22. $foo->name = 'blubber';
  23. $foo->getValidName = function($obj) {
  24.     return htmlspecialchars($obj->name);
  25. };
  26.  
  27. $foo->number = 13;
  28. echo $foo->getValidNumber() . '<br />';
  29. echo $foo->getValidName();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement