Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Update: This is not a catchable fatal error anymore in php 7. Instead an "exception" is thrown. An "exception" (in scare quotes) that is not derived from <a href="http://docs.php.net/class.exception" rel="noreferrer">Exception</a> but <a href="http://docs.php.net/class.error" rel="noreferrer">Error</a>; it's still a <a href="http://docs.php.net/class.throwable" rel="noreferrer">Throwable</a> and can be handled with a normal try-catch block. see <a href="https://wiki.php.net/rfc/throwable-interface" rel="noreferrer">https://wiki.php.net/rfc/throwable-interface</a></p> <p>E.g.</p> <pre><code>&lt;?php class ClassA { public function method_a (ClassB $b) { echo 'method_a: ', get_class($b), PHP_EOL; } } class ClassWrong{} class ClassB{} class ClassC extends ClassB {} foreach( array('ClassA', 'ClassWrong', 'ClassB', 'ClassC') as $cn ) { try{ $a = new ClassA; $a-&gt;method_a(new $cn); } catch(Error $err) { echo "catched: ", $err-&gt;getMessage(), PHP_EOL; } } echo 'done.'; </code></pre> <p>prints</p> <pre><code>catched: Argument 1 passed to ClassA::method_a() must be an instance of ClassB, instance of ClassA given, called in [...] catched: Argument 1 passed to ClassA::method_a() must be an instance of ClassB, instance of ClassWrong given, called in [...] method_a: ClassB method_a: ClassC done. </code></pre> <hr> <p>Old answer for pre-php7 versions:<br> <a href="http://docs.php.net/errorfunc.constants" rel="noreferrer">http://docs.php.net/errorfunc.constants</a> says:</p> <blockquote>E_RECOVERABLE_ERROR ( integer )<br /> Catchable fatal error. It indicates that a probably dangerous error occured, but did not leave the Engine in an unstable state. If the error is not caught by a user defined handle (see also <a href="http://docs.php.net/manual/en/function.set-error-handler.php" rel="noreferrer">set_error_handler()</a>), the application aborts as it was an E_ERROR. </blockquote> <p>see also: <a href="http://derickrethans.nl/erecoverableerror.html" rel="noreferrer">http://derickrethans.nl/erecoverableerror.html</a></p> <p>e.g.</p> <pre><code>function myErrorHandler($errno, $errstr, $errfile, $errline) { if ( E_RECOVERABLE_ERROR===$errno ) { echo "'catched' catchable fatal error\n"; return true; } return false; } set_error_handler('myErrorHandler'); class ClassA { public function method_a (ClassB $b) {} } class ClassWrong{} $a = new ClassA; $a-&gt;method_a(new ClassWrong); echo 'done.'; </code></pre> <p>prints</p> <pre><code>'catched' catchable fatal error done. </code></pre> <p>edit: But you can "make" it an exception you can handle with a try-catch block</p> <pre><code>function myErrorHandler($errno, $errstr, $errfile, $errline) { if ( E_RECOVERABLE_ERROR===$errno ) { echo "'catched' catchable fatal error\n"; throw new ErrorException($errstr, $errno, 0, $errfile, $errline); // return true; } return false; } set_error_handler('myErrorHandler'); class ClassA { public function method_a (ClassB $b) {} } class ClassWrong{} try{ $a = new ClassA; $a-&gt;method_a(new ClassWrong); } catch(Exception $ex) { echo "catched\n"; } echo 'done.'; </code></pre> <p>see: <a href="http://docs.php.net/ErrorException" rel="noreferrer">http://docs.php.net/ErrorException</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload