|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-05-21 07:14 UTC] 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 } PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 06 13:00:01 2026 UTC |
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.