Skip to content

Commit 73596c5

Browse files
committed
Partial fix for bug #75426
This does not print the exact line of the comma, but rather the line of the previous element. This should generally be "good enough", as the line number is close (off by one) to the actual issue now. Previously it would point to the start of the array, which may be very far away.
1 parent 7b3f8e7 commit 73596c5

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Zend/tests/bug75426.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #75426: "Cannot use empty array elements" reports wrong position
3+
--FILE--
4+
<?php
5+
$a = [
6+
1,
7+
2,
8+
3,
9+
,
10+
5,
11+
6,
12+
];
13+
?>
14+
--EXPECTF--
15+
Fatal error: Cannot use empty array elements in arrays in %s on line 5

Zend/zend_compile.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6920,6 +6920,7 @@ static inline void zend_ct_eval_greater(zval *result, zend_ast_kind kind, zval *
69206920
static zend_bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */
69216921
{
69226922
zend_ast_list *list = zend_ast_get_list(ast);
6923+
zend_ast *last_elem_ast = NULL;
69236924
uint32_t i;
69246925
zend_bool is_constant = 1;
69256926

@@ -6932,6 +6933,10 @@ static zend_bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */
69326933
zend_ast *elem_ast = list->child[i];
69336934

69346935
if (elem_ast == NULL) {
6936+
/* Report error at line of last non-empty element */
6937+
if (last_elem_ast) {
6938+
CG(zend_lineno) = zend_ast_get_lineno(last_elem_ast);
6939+
}
69356940
zend_error(E_COMPILE_ERROR, "Cannot use empty array elements in arrays");
69366941
}
69376942

@@ -6943,6 +6948,8 @@ static zend_bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */
69436948
) {
69446949
is_constant = 0;
69456950
}
6951+
6952+
last_elem_ast = elem_ast;
69466953
}
69476954

69486955
if (!is_constant) {

0 commit comments

Comments
 (0)