How can I catch a "catchable fatal error" on PHP type hinting?

Posted by Ho on Stack Overflow See other posts from Stack Overflow or by Ho
Published on 2010-03-18T08:59:03Z Indexed on 2010/03/18 9:01 UTC
Read the original article Hit count: 287

Filed under:
|
|

Hello, I am trying to implement Type Hinting of PHP5 on one of my class,

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

class ClassB {}
class ClassWrong{}

Correct usage:

$a = new ClassA;
$a->method_a(new ClassB);

producing error:

$a = new ClassA;
$a->method_a(new ClassWrong);

Catchable fatal error: Argument 1 passed to ClassA::method_a() must be an instance of ClassB, instance of ClassWrong given...

May I know if it is possible to catch that error(since it says "catchable")? and if yes, how?

Thank you.

© Stack Overflow or respective owner

Related posts about php

Related posts about type-hinting