php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69640 Unhandled EngineExceptions thrown from userland do not produce any output
Submitted: 2015-05-15 13:53 UTC Modified: 2015-05-18 03:04 UTC
From: contact at jubianchi dot fr Assigned: laruence (profile)
Status: Closed Package: *General Issues
PHP Version: master-Git-2015-05-15 (Git) OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: contact at jubianchi dot fr
New email:
PHP Version: OS:

 

 [2015-05-15 13:53 UTC] contact at jubianchi dot fr
Description:
------------
Today, I was playing with EngineException when I saw something that might be a bug.

EngineException are throwable from userland but if we do so, and do not handle the exception, PHP exits with a status 254 and produces no output.

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

// http://3v4l.org/sLnOI

throw new \EngineException('I mess everything up! :trollface:');

Expected result:
----------------
Fatal error: Uncaught exception 'EngineException' with message 'I mess everything up! :trollface:' in /in/3TbdX:5


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-05-15 14:25 UTC] laruence@php.net
maybe we should disallow initialize a engineException/ParserExcetpion etc in userland?

Anyway, a quick fix is set type if it is zero:

 /* This function doesn't return if it uses E_ERROR */
 ZEND_API void zend_exception_error(zend_object *ex, int severity) /* {{{ */
@@ -914,6 +914,10 @@ ZEND_API void zend_exception_error(zend_object *ex, int severity) /* {{{ */
 		zend_long line = zval_get_long(GET_PROPERTY_SILENT(&exception, "line"));
 		zend_long code = zval_get_long(GET_PROPERTY_SILENT(&exception, "code"));

+		if (UNEXPECTED(code == 0)) {
+			code = E_ERROR;
+		}
+
 		if (ce_exception == type_exception_ce && strstr(message->val, ", called in ")) {
 			zend_error_helper(code, file->val, line, "%s and defined", message->val);
 		} else {
 [2015-05-15 14:51 UTC] contact at jubianchi dot fr
> maybe we should disallow initialize a engineException/ParserExcetpion etc in userland?

I think EngineException/ParserExcetpion should not be allowed in userland code. When they are used they can produce too much side effects, i.e a user exception handled as if it were an actual catchable fatal error.
 [2015-05-15 17:55 UTC] rdlowrey@php.net
There seems to be a leak in the latest master as well which is visible using a debug build:

[daniel@centos aerys]$ php7 -a
Interactive shell

php > $test = new TypeException("test");
php > throw new \RuntimeException;

Warning: Uncaught exception 'RuntimeException' in php shell code:1
Stack trace:
#0 {main}
  thrown in php shell code on line 1
php > exit
[Fri May 15 13:48:52 2015]  Script:  '-'
/home/daniel/dev/c/php-src/Zend/zend_objects.c(145) :  Freeing 0xB7464280 (136 bytes), script=-
=== Total 1 memory leaks detected ===
 [2015-05-15 18:32 UTC] rdlowrey@php.net
Actually my previous comment is unrelated to the `EngineException` issue. The memory leak only occurs with an uncaught exception. Please disregard the above.
 [2015-05-16 15:07 UTC] laruence@php.net
-Assigned To: +Assigned To: laruence
 [2015-05-18 03:04 UTC] laruence@php.net
-Status: Assigned +Status: Closed
 [2015-05-18 03:04 UTC] laruence@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2015-05-18 03:19 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a5f408c91bb4403332116237cfebbdd6b7c6e5ab
Log: 1. Fixed bug #69640 Unhandled EngineExceptions thrown from userland do not produce any output
 [2016-07-20 11:38 UTC] davey@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a5f408c91bb4403332116237cfebbdd6b7c6e5ab
Log: 1. Fixed bug #69640 Unhandled EngineExceptions thrown from userland do not produce any output
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 06:01:29 2025 UTC