Bug #69678 [Nab]: Exception handling consistency with namespace

From: Date: Thu, 21 May 2015 09:51:27 +0000
Subject: Bug #69678 [Nab]: Exception handling consistency with namespace
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192801@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69678&edit=1 ID: 69678 User updated by: pahanmipt at mail dot ru Reported by: pahanmipt at mail dot ru Summary: Exception handling consistency with namespace Status: Not a bug Type: Bug Package: Scripting Engine problem Operating System: Ubuntu 14.04 PHP Version: 5.6.9 Block user comment: N Private report: N New Comment: Ok. Could we require it when the exception throwed at try block ? Previous Comments: ------------------------------------------------------------------------ [2015-05-21 08:29:01] nikic@php.net We don't require the exception class to exist in the catch() clause, because it might be loaded at a later time or different configuration. A simple example of why this is useful is this: try { // ... } catch (Exception $e) { // ... } catch (BaseException $e) { // ... } This allows you to catch all exceptions on both PHP 5 and 7. You will not get an error on PHP 5 because "BaseException" does not exist there. ------------------------------------------------------------------------ [2015-05-21 07:14:41] pahanmipt at mail dot ru Description: ------------ The exception from global namespace is not catched at namespaced class methods if exception name is not fully qualified at catch block and no error occured. Test script: --------------- https://github.com/0x-ff/php-gotchas/blob/master/intersting_exception_handling.php Expected result: ---------------- I think that it would be a fatal error to consistent behaviour with fatal at throw new GlobalException(); // not fully qualified => not found catch(GlobalException $e) { // not fully qualified => MUST BE FATAL not found Actual result: -------------- The exception class GlobalException at test script catches at class only if fully qualified namespace ...; try { throw new \GlobalException(""); } catch (GlobalException $e) { // Not catched here and no error occured that its not fully qualified, just silently ignored that exception } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69678&edit=1

« previous php.bugs (#192801) next »