Hi All

I was going though this post as I was encountering the same problem. The solution mentioned there works.

But I have a question, Suppose I have defined ClassA in a different file with the following code:

PHP Code:
namespace ABC;

class 
ClassA {
  public function 
method_a (ClassB $b) {}

Now, my colleagues needs to use it, so they use the following code:

PHP Code:
use ABC;

class 
ClassWrong{}

try{
  
$a = new ABC\ClassA;
  
$a->method_a(new ClassWrong);
}
catch(
Exception $ex) {
  echo 
"catched\n";

and in order to raise the custom exception, they need to add the following codes as well

PHP Code:

function myErrorHandler($errno$errstr$errfile$errline) {
  if ( 
E_RECOVERABLE_ERROR===$errno ) {
    echo 
"'catched' catchable fatal error\n";
    throw new 
ErrorException($errstr$errno0$errfile$errline);
    
// return true;
  
}
  return 
false;
}
set_error_handler('myErrorHandler'); 
So, I was wondering is there anyway I can add the myErrorHandler() and set_error_handler functions in the parent class so that my colleagues do have to add those code in their file?


Thanks in advance for any inputs