PHP forward magic methods


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function __call($name, $arguments) {
  2. if(method_exists($this->Email, $name)) {
  3. call_user_func_array(array($this->Email,$name),$arguments);
  4. } else {
  5. trigger_error('Method '.$name.' does not exist', E_USER_ERROR);
  6. }
  7. }
  8. function __get($name) {
  9. if(property_exists($this->Email, $name)) {
  10. return $this->Email->$name;
  11. } else {
  12. trigger_error('Property '.$name.' does not exist', E_USER_ERROR);
  13. }
  14. }
  15. function __set($name, $value) {
  16. if(property_exists($this->Email, $name)) {
  17. $this->Email->$name = $value;
  18. } else {
  19. trigger_error('Property '.$name.' does not exist', E_USER_ERROR);
  20. }
  21. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.