Your location:Tech News>News>Script>__call PHP magic methods of use and __callStatic

Latest News

__call PHP magic methods of use and __callStatic

Author:fsadmin

Views:

  // magic methods __call

  class Human {

  private function t () {

  }

  public function __call ($ method, $ arg) {

  echo ''You want me to call a method that does not exist'', $ method, ''method
'';

  echo ''also pass a parameter
'';

  echo print_r ($ arg), ''
'';

  }

  public static function __callStatic ($ method, $ arg) {

  echo ''You want to call my non-existent'', $ method, ''static method
'';

  echo ''also pass a parameter
'';

  echo print_r ($ arg), ''
'';

  }

  }

  $ Ha = new Human ();

  // example1

  $ Ha-> t (1,2,3);

  echo ''
'';

  // example2

  $ Ha-> say ( ''a'', ''b'', ''c'');

  echo ''
'';

  // example3

  $ Ha :: run ( ''d'', ''e'', ''f'');

Recommend article

Relate article