PHP custom exception message -


i'm trying display custom error message if method doesnt' exist method() or getmethod():

public function __call($name, $args = array()){   $getter = "get{$name}";    try {     echo call_user_func_array(array(&$this, $getter), $args);   } catch (exception $e) {      trigger_error($e->getfile.' on line '.$e->getline.': method '.$name.' not defined.', e_user_error)   } } 

but doesn't work. "connection closed remote server" message in browser :|

you use method_exists function:

if(!method_exists($this, $name)) {     // trigger_error(...); } 

if wanted data such invalid method called from, can use debug_backtrace:

class x {     public function __call($name, $a)     {         $backtrace = debug_backtrace();         $backtrace = $backtrace[1];         // $backtrace['file']         // $backtrace['line']         // $backtrace['function']         // $backtrace['class']         // $backtrace['object']     } }  $o = new x(); $o->hello(); 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -