Dynamic Methods

You can also create "virtual" methods that will be handled via the special __call() method.


class math {
    function __call($name, $args)
        switch ($name) {
            case 'add':
                return array_sum($args);
            case 'subtract':
                $val = array_shift($args);
                foreach ($args as $v) $val /= $v;
                return $val;

$m = new math();
echo $m->add(1,2); // will print 3
echo $m->subtract(8,2); // will print 4


Loading ...

Related Results :

  1. Dynamic Methods
Note :
  • Related Posts are generally User Blog posts.
  • or Other tutorials from other networks of w3clan.com.
  • Any registered user can create related posts based on search term tags.

About the Author