Skip to content

Commit 381e020

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix lineno in function redeclaration error
2 parents ce99ade + de7ef3f commit 381e020

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ PHP NEWS
1515
. Fixed bug GH-16371 (Assertion failure in Zend/zend_weakrefs.c:646). (Arnaud)
1616
. Fixed bug GH-16515 (Incorrect propagation of ZEND_ACC_RETURN_REFERENCE for
1717
call trampoline). (ilutov)
18+
. Fixed bug GH-16509 (Incorrect line number in function redeclaration error).
19+
(ilutov)
1820

1921
- Curl:
2022
. Fixed bug GH-16302 (CurlMultiHandle holds a reference to CurlHandle if

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 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
@@ -1202,7 +1202,7 @@ static zend_never_inline ZEND_COLD ZEND_NORETURN void do_bind_function_error(zen
12021202
zend_error_noreturn(error_level, "Cannot redeclare %s() (previously declared in %s:%d)",
12031203
op_array ? ZSTR_VAL(op_array->function_name) : ZSTR_VAL(old_function->common.function_name),
12041204
ZSTR_VAL(old_function->op_array.filename),
1205-
old_function->op_array.opcodes[0].lineno);
1205+
old_function->op_array.line_start);
12061206
} else {
12071207
zend_error_noreturn(error_level, "Cannot redeclare %s()",
12081208
op_array ? ZSTR_VAL(op_array->function_name) : ZSTR_VAL(old_function->common.function_name));
@@ -7684,6 +7684,7 @@ static void zend_compile_func_decl(znode *result, zend_ast *ast, bool toplevel)
76847684
} else if (toplevel) {
76857685
/* Only register the function after a successful compile */
76867686
if (UNEXPECTED(zend_hash_add_ptr(CG(function_table), lcname, op_array) == NULL)) {
7687+
CG(zend_lineno) = decl->start_lineno;
76877688
do_bind_function_error(lcname, op_array, true);
76887689
}
76897690
}

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(E_ERROR, "Cannot redeclare %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(E_ERROR, "Cannot redeclare %s()", ZSTR_VAL(function1->common.function_name));
187187
}

0 commit comments

Comments
 (0)