Bug #70030 [Opn->Nab]: try does not catch

From: Date: Wed, 08 Jul 2015 23:45:15 +0000
Subject: Bug #70030 [Opn->Nab]: try does not catch
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-194236@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70030&edit=1 ID: 70030 Updated by: requinix@php.net Reported by: bugzilla77 at gmail dot com Summary: try does not catch -Status: Open +Status: Not a bug Type: Bug Package: *General Issues Operating System: Windows 7 PHP Version: 5.6.10 Block user comment: N Private report: N New Comment: As the error message clearly states, it's a fatal error. Not an exception. You cannot catch errors like that. Do the responsible thing and check for valid objects before you try to call member methods. With that said, PHP 7 is turning errors like this into exceptions so you will be able to catch them. However it will be an Error, which is not a descendant of Exception, so you would need something else in your catch block. https://wiki.php.net/rfc/throwable-interface http://3v4l.org/bhBLr (see 7.0.0alpha2) Previous Comments: ------------------------------------------------------------------------ [2015-07-08 22:11:15] bugzilla77 at gmail dot com Description: ------------ try does not catch Test script: --------------- <?php $d=new DOMDocument(); $d->loadHTML('<html></html>'); $p=new DOMXPath($d); try{ $p->query('//html/head')->item(0)->getAttribute('rel'); }catch(Exception $e){ print('Catched'); } ?> Expected result: ---------------- Catched Actual result: -------------- Fatal error: Call to a member function getAttribute() on null in C:\htdocs\test.pl\1.php on line 11 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70030&edit=1

« previous php.bugs (#194236) next »