Skip to content

Fix lineno in backtrace of multi-line function calls #8818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Zend/tests/gh8810_1.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
GH-8810: Fix reported line number of multi-line function call
--FILE--
<?php

function foo($bar, $baz) {
throw new Exception();
}

foo
(
'bar',
'baz',
);

?>
--EXPECTF--
Fatal error: Uncaught Exception in %s:4
Stack trace:
#0 %s(7): foo('bar', 'baz')
#1 {main}
thrown in %s on line 4
23 changes: 23 additions & 0 deletions Zend/tests/gh8810_2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
GH-8810: Fix reported line number of multi-line method call
--FILE--
<?php

class A {
public function b() {
throw new Exception();
}
}

(new A())
->
b
();

?>
--EXPECTF--
Fatal error: Uncaught Exception in %s:5
Stack trace:
#0 %s(11): A->b()
#1 {main}
thrown in %s on line 5
19 changes: 19 additions & 0 deletions Zend/tests/gh8810_3.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
GH-8810: Fix reported line number of multi-line closure call
--FILE--
<?php

(function () {
throw new Exception();
})
(
'foo',
);

?>
--EXPECTF--
Fatal error: Uncaught Exception in %s:4
Stack trace:
#0 %s(6): {closure}('foo')
#1 {main}
thrown in %s on line 4
19 changes: 19 additions & 0 deletions Zend/tests/gh8810_4.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
GH-8810: Fix reported line number of multi-line dynamic call
--FILE--
<?php

function foo() {
throw new Exception();
}

'foo'
();

?>
--EXPECTF--
Fatal error: Uncaught Exception in %s:4
Stack trace:
#0 %s(8): foo()
#1 {main}
thrown in %s on line 4
16 changes: 16 additions & 0 deletions Zend/tests/gh8810_5.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
GH-8810: Fix reported line number of multi-line assert call
--FILE--
<?php

assert(
false,
);

?>
--EXPECTF--
Fatal error: Uncaught AssertionError: assert(false) in %s:3
Stack trace:
#0 %s(3): assert(false, 'assert(false)')
#1 {main}
thrown in %s on line 3
23 changes: 23 additions & 0 deletions Zend/tests/gh8810_6.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
GH-8810: Fix reported line number of multi-line static call
--FILE--
<?php

class A {
public static function b() {
throw new Exception();
}
}

A
::
b
();

?>
--EXPECTF--
Fatal error: Uncaught Exception in %s:5
Stack trace:
#0 %s(11): A::b()
#1 {main}
thrown in %s on line 5
22 changes: 22 additions & 0 deletions Zend/tests/gh8810_7.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
GH-8810: Fix reported line number of multi-line new call
--FILE--
<?php

class A {
public function __construct() {
throw new Exception();
}
}

new
A
();

?>
--EXPECTF--
Fatal error: Uncaught Exception in %s:5
Stack trace:
#0 %s(10): A->__construct()
#1 {main}
thrown in %s on line 5
33 changes: 17 additions & 16 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -3623,7 +3623,7 @@ ZEND_API zend_uchar zend_get_call_op(const zend_op *init_op, zend_function *fbc)
}
/* }}} */

static bool zend_compile_call_common(znode *result, zend_ast *args_ast, zend_function *fbc) /* {{{ */
static bool zend_compile_call_common(znode *result, zend_ast *args_ast, zend_function *fbc, uint32_t lineno) /* {{{ */
{
zend_op *opline;
uint32_t opnum_init = get_next_op_number() - 1;
Expand Down Expand Up @@ -3660,6 +3660,7 @@ static bool zend_compile_call_common(znode *result, zend_ast *args_ast, zend_fun
if (may_have_extra_named_args) {
opline->extended_value = ZEND_FCALL_MAY_HAVE_EXTRA_NAMED_PARAMS;
}
opline->lineno = lineno;
zend_do_extended_fcall_end();
return false;
}
Expand All @@ -3678,7 +3679,7 @@ static bool zend_compile_function_name(znode *name_node, zend_ast *name_ast) /*
}
/* }}} */

static void zend_compile_ns_call(znode *result, znode *name_node, zend_ast *args_ast) /* {{{ */
static void zend_compile_ns_call(znode *result, znode *name_node, zend_ast *args_ast, uint32_t lineno) /* {{{ */
{
zend_op *opline = get_next_op();
opline->opcode = ZEND_INIT_NS_FCALL_BY_NAME;
Expand All @@ -3687,11 +3688,11 @@ static void zend_compile_ns_call(znode *result, znode *name_node, zend_ast *args
Z_STR(name_node->u.constant));
opline->result.num = zend_alloc_cache_slot();

zend_compile_call_common(result, args_ast, NULL);
zend_compile_call_common(result, args_ast, NULL, lineno);
}
/* }}} */

static void zend_compile_dynamic_call(znode *result, znode *name_node, zend_ast *args_ast) /* {{{ */
static void zend_compile_dynamic_call(znode *result, znode *name_node, zend_ast *args_ast, uint32_t lineno) /* {{{ */
{
if (name_node->op_type == IS_CONST && Z_TYPE(name_node->u.constant) == IS_STRING) {
const char *colon;
Expand Down Expand Up @@ -3721,7 +3722,7 @@ static void zend_compile_dynamic_call(znode *result, znode *name_node, zend_ast
zend_emit_op(NULL, ZEND_INIT_DYNAMIC_CALL, NULL, name_node);
}

zend_compile_call_common(result, args_ast, NULL);
zend_compile_call_common(result, args_ast, NULL, lineno);
}
/* }}} */

Expand Down Expand Up @@ -4015,7 +4016,7 @@ static zend_result zend_compile_func_cuf(znode *result, zend_ast_list *args, zen
}
/* }}} */

static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string *name, zend_function *fbc) /* {{{ */
static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string *name, zend_function *fbc, uint32_t lineno) /* {{{ */
{
if (EG(assertions) >= 0) {
znode name_node;
Expand Down Expand Up @@ -4050,7 +4051,7 @@ static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string
zend_ast_list_add((zend_ast *) args, arg);
}

zend_compile_call_common(result, (zend_ast*)args, fbc);
zend_compile_call_common(result, (zend_ast*)args, fbc, lineno);

opline = &CG(active_op_array)->opcodes[check_op_number];
opline->op2.opline_num = get_next_op_number();
Expand Down Expand Up @@ -4377,7 +4378,7 @@ static void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{

if (name_ast->kind != ZEND_AST_ZVAL || Z_TYPE_P(zend_ast_get_zval(name_ast)) != IS_STRING) {
zend_compile_expr(&name_node, name_ast);
zend_compile_dynamic_call(result, &name_node, args_ast);
zend_compile_dynamic_call(result, &name_node, args_ast, ast->lineno);
return;
}

Expand All @@ -4386,9 +4387,9 @@ static void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{
if (runtime_resolution) {
if (zend_string_equals_literal_ci(zend_ast_get_str(name_ast), "assert")
&& !is_callable_convert) {
zend_compile_assert(result, zend_ast_get_list(args_ast), Z_STR(name_node.u.constant), NULL);
zend_compile_assert(result, zend_ast_get_list(args_ast), Z_STR(name_node.u.constant), NULL, ast->lineno);
} else {
zend_compile_ns_call(result, &name_node, args_ast);
zend_compile_ns_call(result, &name_node, args_ast, ast->lineno);
}
return;
}
Expand All @@ -4405,7 +4406,7 @@ static void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{

/* Special assert() handling should apply independently of compiler flags. */
if (fbc && zend_string_equals_literal(lcname, "assert") && !is_callable_convert) {
zend_compile_assert(result, zend_ast_get_list(args_ast), lcname, fbc);
zend_compile_assert(result, zend_ast_get_list(args_ast), lcname, fbc, ast->lineno);
zend_string_release(lcname);
zval_ptr_dtor(&name_node.u.constant);
return;
Expand All @@ -4417,7 +4418,7 @@ static void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{
|| (fbc->type == ZEND_USER_FUNCTION && (CG(compiler_options) & ZEND_COMPILE_IGNORE_OTHER_FILES) && fbc->op_array.filename != CG(active_op_array)->filename)
) {
zend_string_release_ex(lcname, 0);
zend_compile_dynamic_call(result, &name_node, args_ast);
zend_compile_dynamic_call(result, &name_node, args_ast, ast->lineno);
return;
}

Expand All @@ -4436,7 +4437,7 @@ static void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{
opline = zend_emit_op(NULL, ZEND_INIT_FCALL, NULL, &name_node);
opline->result.num = zend_alloc_cache_slot();

zend_compile_call_common(result, args_ast, fbc);
zend_compile_call_common(result, args_ast, fbc, ast->lineno);
}
}
/* }}} */
Expand Down Expand Up @@ -4500,7 +4501,7 @@ static void zend_compile_method_call(znode *result, zend_ast *ast, uint32_t type
}
}

if (zend_compile_call_common(result, args_ast, fbc)) {
if (zend_compile_call_common(result, args_ast, fbc, zend_ast_get_lineno(method_ast))) {
if (short_circuiting_checkpoint != zend_short_circuiting_checkpoint()) {
zend_error_noreturn(E_COMPILE_ERROR,
"Cannot combine nullsafe operator with Closure creation");
Expand Down Expand Up @@ -4597,7 +4598,7 @@ static void zend_compile_static_call(znode *result, zend_ast *ast, uint32_t type
}
}

zend_compile_call_common(result, args_ast, fbc);
zend_compile_call_common(result, args_ast, fbc, zend_ast_get_lineno(method_ast));
}
/* }}} */

Expand Down Expand Up @@ -4629,7 +4630,7 @@ static void zend_compile_new(znode *result, zend_ast *ast) /* {{{ */
SET_NODE(opline->op1, &class_node);
}

zend_compile_call_common(&ctor_result, args_ast, NULL);
zend_compile_call_common(&ctor_result, args_ast, NULL, ast->lineno);
zend_do_free(&ctor_result);
}
/* }}} */
Expand Down
6 changes: 4 additions & 2 deletions Zend/zend_language_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -1263,8 +1263,10 @@ function_call:
{ $$ = zend_ast_create(ZEND_AST_STATIC_CALL, $1, $3, $4); }
| variable_class_name T_PAAMAYIM_NEKUDOTAYIM member_name argument_list
{ $$ = zend_ast_create(ZEND_AST_STATIC_CALL, $1, $3, $4); }
| callable_expr argument_list
{ $$ = zend_ast_create(ZEND_AST_CALL, $1, $2); }
| callable_expr { $<num>$ = CG(zend_lineno); } argument_list {
$$ = zend_ast_create(ZEND_AST_CALL, $1, $3);
$$->lineno = $<num>2;
}
;

class_name:
Expand Down
2 changes: 1 addition & 1 deletion ext/intl/tests/dateformat_calendars_variant3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ string(47) "Sunday, January 1, 2012 at 5:12:00 AM GMT+05:12"
string(47) "Sunday, January 1, 2012 at 5:12:00 AM GMT+05:12"
string(44) "Sunday, 6 Tevet 5772 at 5:12:00 AM GMT+05:12"

Fatal error: Uncaught IntlException: IntlDateFormatter::__construct(): datefmt_create: Invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object in %sdateformat_calendars_variant3.php:27
Fatal error: Uncaught IntlException: IntlDateFormatter::__construct(): datefmt_create: Invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object in %sdateformat_calendars_variant3.php:%d
Stack trace:
#0 %sdateformat_calendars_variant3.php(%d): IntlDateFormatter->__construct('en_US@calendar=...', 0, 0, 'GMT+05:12', -1)
#1 {main}
Expand Down