Skip to content
Open
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
37 changes: 37 additions & 0 deletions Zend/tests/gh18105.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--TEST--
GH-18105 (Wrong line & file on error trace with trait default parameter)
--FILE--
<?php

file_put_contents(__DIR__ . '/gh18105_defs.inc', <<<'PHP'
<?php
class ThrowableParam {
public function __construct() {
throw new Exception('thrown here');
}
}
trait TraitInASeparateFile {
public function execute(ThrowableParam $param = new ThrowableParam): void {}
}
PHP);

include __DIR__ . '/gh18105_defs.inc';

class Foo {
use TraitInASeparateFile;
}

try {
(new Foo)->execute();
} catch (Exception $e) {
echo basename($e->getFile()), "\n";
echo $e->getLine(), "\n";
}
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/gh18105_defs.inc');
?>
--EXPECT--
gh18105_defs.inc
4
12 changes: 12 additions & 0 deletions Zend/zend_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1099,8 +1099,14 @@ static zend_result ZEND_FASTCALL zend_ast_evaluate_inner(

zend_function *ctor = Z_OBJ_HT_P(result)->get_constructor(Z_OBJ_P(result));
if (ctor) {
zend_string *prev_filename = EG(filename_override);
zend_long prev_lineno = EG(lineno_override);
EG(filename_override) = NULL;
EG(lineno_override) = -1;
zend_call_known_function(
ctor, Z_OBJ_P(result), Z_OBJCE_P(result), NULL, 0, NULL, args);
EG(filename_override) = prev_filename;
EG(lineno_override) = prev_lineno;
}

zend_array_destroy(args);
Expand All @@ -1120,8 +1126,14 @@ static zend_result ZEND_FASTCALL zend_ast_evaluate_inner(

zend_function *ctor = Z_OBJ_HT_P(result)->get_constructor(Z_OBJ_P(result));
if (ctor) {
zend_string *prev_filename = EG(filename_override);
zend_long prev_lineno = EG(lineno_override);
EG(filename_override) = NULL;
EG(lineno_override) = -1;
zend_call_known_instance_method(
ctor, Z_OBJ_P(result), NULL, args_ast->children, args);
EG(filename_override) = prev_filename;
EG(lineno_override) = prev_lineno;
}

for (uint32_t i = 0; i < args_ast->children; i++) {
Expand Down
Loading