Is there a function like the magic method __call() for global scope in php? -


if call made undefined method in class, magic method __call can intercept call, handle situation see fit: http://www.php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.methods

is there mechanism provided in php whereby can same thing functions in global scope. point best illustrated code:

    <?php     function return_some_array(){       $a = array();       //do stuff array       return array();     }      // call function so:     $give_me_array = return_some_array();      // want array not contain zeroes, nulls etc.     // call:      $give_me_array_filtered = return_some_array_filtered();      // haven't defined return_some_array_filtered() anywhere.     // instead so:      function __magic_call($function_name_passed_automatically){        preg_match('/(.*)_filtered$/', $function_name_passed_automatically, $matches);       $function_name_that_i_defined_earlier_called_return_some_array = $matches[1];       if($matches){         $result = call_user_func($function_name_that_i_defined_earlier_called_return_some_array);         $filtered = array_filter($result);         return $filtered;       }     }      //so now, call return_some_other_array_filtered() , work provided had defined return_some_other_array().     //or donkey_filtered() work, provided had defined donkey() somewhere.     ?> 

is @ possible?

not such.

if had made static method return_some_array_filtered::go() use php5's autoload() facility dynamically create class , method. after creation call proceeds usual. may want implement callstatic() on class. beware dynamically creating class scratch (without include()) in php non-trivial.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -