Skip to content

Commit e949f30

Browse files
committed
Fixed bug #72089: Throw Error on require failure
It should be noted that we still throw the usual fopen warnings, but the final fatal error becomes an Error exception. Combine with @ to suppress FS warnings. Closes GH-5641.
1 parent 4ce4770 commit e949f30

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ PHP NEWS
2727
. Fixed bug #79467 (data:// wrappers are writable). (cmb)
2828
. Implemented FR #47074 (phpinfo() reports "On" as 1 for the some
2929
extensions). (cmb)
30+
. Implemented FR #72089 (require() throws fatal error instead of exception).
31+
(Nikita)
3032

3133
- BZ2:
3234
. Fixed bug #71263 (fread() does not report bzip2.decompress errors). (cmb)

Zend/tests/include_stat_is_quiet.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ try {
2727
--EXPECTF--
2828
Warning: require_once(doesnt_exist.php): Failed to open stream: No such file or directory in %s on line %d
2929

30-
Fatal error: require_once(): Failed opening required 'doesnt_exist.php' (include_path='test://foo:test://bar') in %s on line %d
30+
Fatal error: Uncaught Error: Failed opening required 'doesnt_exist.php' (include_path='test://foo:test://bar') in %s:%d
31+
Stack trace:
32+
#0 {main}
33+
thrown in %s on line %d

main/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ static ZEND_COLD void php_message_handler_for_zend(zend_long message, const void
16181618
php_error_docref("function.include", E_WARNING, "Failed opening '%s' for inclusion (include_path='%s')", php_strip_url_passwd((char *) data), STR_PRINT(PG(include_path)));
16191619
break;
16201620
case ZMSG_FAILED_REQUIRE_FOPEN:
1621-
php_error_docref("function.require", E_COMPILE_ERROR, "Failed opening required '%s' (include_path='%s')", php_strip_url_passwd((char *) data), STR_PRINT(PG(include_path)));
1621+
zend_throw_error(NULL, "Failed opening required '%s' (include_path='%s')", php_strip_url_passwd((char *) data), STR_PRINT(PG(include_path)));
16221622
break;
16231623
case ZMSG_FAILED_HIGHLIGHT_FOPEN:
16241624
php_error_docref(NULL, E_WARNING, "Failed opening '%s' for highlighting", php_strip_url_passwd((char *) data));

tests/lang/bug35176.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ require_once('nonexisiting.php');
1212
<br />
1313
<b>Warning</b>: require_once(nonexisiting.php) [<a href='/function.require-once.html'>function.require-once.html</a>]: Failed to open stream: No such file or directory in <b>%sbug35176.php</b> on line <b>2</b><br />
1414
<br />
15-
<b>Fatal error</b>: require_once() [<a href='/function.require.html'>function.require.html</a>]: Failed opening required 'nonexisiting.php' (%s) in <b>%sbug35176.php</b> on line <b>2</b><br />
15+
<b>Fatal error</b>: Uncaught Error: Failed opening required 'nonexisiting.php' (include_path='%s') in %s:%d
16+
Stack trace:
17+
#0 {main}
18+
thrown in <b>%sbug35176.php</b> on line <b>2</b><br />

0 commit comments

Comments
 (0)