Skip to content

Commit 77a7d34

Browse files
authored
Fix GH-22849: error_include_args=1 mishandled for include() (#22851)
include and friends aren't functions, but constructs of the engine. Special-case them and snarf their argument for display.
1 parent b06dfa2 commit 77a7d34

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

Zend/tests/gh22849.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
PHP 8.6 error_include_args=1 mishandled for include()
3+
--INI--
4+
error_include_args=On
5+
--FILE--
6+
<?php
7+
8+
function foo() {
9+
include("does not exist");
10+
include_once("does not exist");
11+
require("does not exist");
12+
}
13+
14+
foo(1, 2);
15+
?>
16+
--EXPECTF--
17+
Warning: include('does not exist'): Failed to open stream: No such file or directory in %s on line %d
18+
19+
Warning: include('does not exist'): Failed opening 'does not exist' for inclusion (include_path='%s') in %s on line %d
20+
21+
Warning: include_once('does not exist'): Failed to open stream: No such file or directory in %s on line %d
22+
23+
Warning: include_once('does not exist'): Failed opening 'does not exist' for inclusion (include_path='%s') in %s on line %d
24+
25+
Warning: require('does not exist'): Failed to open stream: No such file or directory in %s on line %d
26+
27+
Fatal error: Uncaught Error: Failed opening required 'does not exist' (include_path='%s') in %s:%d
28+
Stack trace:
29+
#0 %s(%d): foo(1, 2)
30+
#1 {main}
31+
thrown in %s on line %d

Zend/zend_exceptions.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,19 @@ ZEND_API zend_string *zend_trace_function_args_to_string(const HashTable *frame)
630630
/* {{{ Gets the currently executing function's arguments as a string. Used by php_verror. */
631631
ZEND_API zend_string *zend_trace_current_function_args_string(void) {
632632
zend_string *dynamic_params = NULL;
633+
/* Special case: require_once/include_once aren't functions, but we
634+
* want to capture their arguments anyways, for i.e. file not found.
635+
*/
636+
zend_execute_data *execute_data = EG(current_execute_data);
637+
if (execute_data && execute_data->func
638+
&& ZEND_USER_CODE(execute_data->func->common.type)
639+
&& (execute_data->opline->opcode == ZEND_INCLUDE_OR_EVAL)) {
640+
zval *inc_filename = RT_CONSTANT(execute_data->opline, execute_data->opline->op1);
641+
smart_str str = {0};
642+
build_trace_args(inc_filename, &str);
643+
return smart_str_extract(&str);
644+
}
645+
633646
/* get a backtrace to snarf function args */
634647
zval backtrace;
635648
zend_fetch_debug_backtrace(&backtrace, /* skip_last */ 0, /* options */ 0, /* limit */ 1);

0 commit comments

Comments
 (0)