Skip to content

Commit 7862b15

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix lineno in function redeclaration error
2 parents 178ee5b + cd8ee4d commit 7862b15

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

Zend/tests/gh16509.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
function test() {
4+
5+
6+
echo 'foo';
7+
}

Zend/tests/gh16509.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
GH-16509: Incorrect lineno reported for function redeclaration
3+
--FILE--
4+
<?php
5+
6+
include __DIR__ . '/gh16509.inc';
7+
include __DIR__ . '/gh16509.inc';
8+
9+
?>
10+
--EXPECTF--
11+
Fatal error: Cannot redeclare function test() (previously declared in %sgh16509.inc:3) in %sgh16509.inc on line 3

Zend/zend_compile.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ static zend_never_inline ZEND_COLD ZEND_NORETURN void do_bind_function_error(zen
12781278
zend_error_noreturn(error_level, "Cannot redeclare function %s() (previously declared in %s:%d)",
12791279
op_array ? ZSTR_VAL(op_array->function_name) : ZSTR_VAL(old_function->common.function_name),
12801280
ZSTR_VAL(old_function->op_array.filename),
1281-
old_function->op_array.opcodes[0].lineno);
1281+
old_function->op_array.line_start);
12821282
} else {
12831283
zend_error_noreturn(error_level, "Cannot redeclare function %s()",
12841284
op_array ? ZSTR_VAL(op_array->function_name) : ZSTR_VAL(old_function->common.function_name));
@@ -8362,6 +8362,7 @@ static zend_op_array *zend_compile_func_decl_ex(
83628362
} else if (toplevel) {
83638363
/* Only register the function after a successful compile */
83648364
if (UNEXPECTED(zend_hash_add_ptr(CG(function_table), lcname, op_array) == NULL)) {
8365+
CG(zend_lineno) = decl->start_lineno;
83658366
do_bind_function_error(lcname, op_array, true);
83668367
}
83678368
}

ext/opcache/zend_accelerator_util_funcs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,13 @@ static zend_always_inline void _zend_accel_function_hash_copy(HashTable *target,
175175
function2 = Z_PTR_P(t);
176176
CG(in_compilation) = 1;
177177
zend_set_compiled_filename(function1->op_array.filename);
178-
CG(zend_lineno) = function1->op_array.opcodes[0].lineno;
178+
CG(zend_lineno) = function1->op_array.line_start;
179179
if (function2->type == ZEND_USER_FUNCTION
180180
&& function2->op_array.last > 0) {
181181
zend_error_noreturn(E_ERROR, "Cannot redeclare function %s() (previously declared in %s:%d)",
182182
ZSTR_VAL(function1->common.function_name),
183183
ZSTR_VAL(function2->op_array.filename),
184-
(int)function2->op_array.opcodes[0].lineno);
184+
(int)function2->op_array.line_start);
185185
} else {
186186
zend_error_noreturn(E_ERROR, "Cannot redeclare function %s()", ZSTR_VAL(function1->common.function_name));
187187
}

0 commit comments

Comments
 (0)