Bug #80009 [Opn->Nab]: Fatal Error is not caught with Throwable

From: Date: Sat, 22 Aug 2020 20:49:36 +0000
Subject: Bug #80009 [Opn->Nab]: Fatal Error is not caught with Throwable
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-228711@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80009&edit=1

 ID:                 80009
 Updated by:         cmb@php.net
 Reported by:        brucekwells at gmail dot com
 Summary:            Fatal Error is not caught with Throwable
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Compile Failure
 Operating System:   Windows 10.0 build 19041 AMD64
 PHP Version:        7.4.9
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php

There is a difference between E_(*_)ERROR and Throwable.
Just try without the try-catch-statement.


Previous Comments:
------------------------------------------------------------------------
[2020-08-22 18:04:44] brucekwells at gmail dot com

Description:
------------
Some Fatal Errors are caught in this script and some are not.

Comment out the "extends TestBase" of the TestExtended class, and this example will catch
the error: Return value of TestExtended::returnString() must be of the type int, string returned

Or change the class in the new statement to an undefined class.  Or change the method call.  Both
are fatal errors, both caught.

But as written, this script does not catch the fatal error.

Test script:
---------------
<?php

try
	{
	class TestBase
		{

		public function returnString() : string
			{
			return __METHOD__;
			}

		}

	class TestExtended extends TestBase
		{

		public function returnString() : int
			{
			return __METHOD__;
			}

		}

	$test = new TestExtended();
	echo $test->returnString();
	}
catch (\Throwable $e)
	{
	echo 'Caught error: ' . $e->getMessage();
	}
phpinfo();



Expected result:
----------------
'Caught error: ' followed by PHP error message is printed, followed by phpinfo() output.

Actual result:
--------------
Fatal error message is printed the standard PHP error handler and is not prefixed by 'Caught
error: '.  phpinfo() is also not printed.


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=80009&edit=1


Thread (6 messages)

« previous php.bugs (#228711) next »