|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28464 catch() does not catch exceptions by interfaces
Submitted: 2004-05-21 02:03 UTC Modified: 2004-07-18 02:12 UTC
From: d at koteroff dot ru Assigned: helly (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.0.0 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: d at koteroff dot ru
New email:
PHP Version: OS:


 [2004-05-21 02:03 UTC] d at koteroff dot ru
Seems PHP does not support exception catching by parent interface (not by parent classes). Why? This is a very powerful method to classify exceptions in programs. 

Documentation says that while comparing type in catch block 'instanceof' operator is used, but following test shows that it is wrong.

I found corresponding code in the source, zend_execute.c:2866, and it searches for parent classes only. Why not use instanceof_function?

Do you have any perspectives about this problem? Can I wrote in my book that PHP will support "interface catching" in the future?

Reproduce code:
interface E {}
class A extends Exception implements E {}
try {
  throw new A();
} catch (E $e) {
  echo $e;

Expected result:
prints exception data

Actual result:
Fatal error: Uncaught exception


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-22 01:55 UTC] php at koteroff dot ru
Still waiting. :-)
Thanks for RC3.
 [2004-07-16 08:40 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

 [2004-07-18 02:07 UTC] d at koteroff dot ru

Still get the same error.
 [2004-07-18 02:12 UTC] d at koteroff dot ru
Sorry, my bad.
All works correct.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 18 08:01:28 2024 UTC