Skip to content

Commit 73f87cf

Browse files
committed
Temporary reset filename and lineno override before autoload
Closes GH-10232.
1 parent c2b671c commit 73f87cf

File tree

6 files changed

+61
-1
lines changed

6 files changed

+61
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.2.17
44

5+
- Core:
6+
. Fixed bug GH-10232 (if autoloading occurs during constant resolution
7+
filename and lineno are identified incorrectly). (ranvis)
8+
59
- Curl:
610
. Fix failing tests due to string changes in libcurl 8.6.0. (Ayesh)
711

Zend/tests/gh10232.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
GH-10232 (Weird behaviour when a file is autoloaded in assignment of a constant)
3+
--FILE--
4+
<?php
5+
6+
set_include_path('gh10232-nonexistent') or exit(1);
7+
chdir(__DIR__) or exit(1);
8+
9+
spl_autoload_register(function () {
10+
trigger_error(__LINE__);
11+
$ex = new Exception();
12+
echo 'Exception on line ', $ex->getLine(), "\n";
13+
require_once __DIR__ . '/gh10232/constant_def.inc';
14+
}, true);
15+
16+
17+
class ConstantRef
18+
{
19+
public const VALUE = ConstantDef::VALUE;
20+
}
21+
22+
ConstantRef::VALUE;
23+
24+
?>
25+
--EXPECTF--
26+
Notice: 7 in %sgh10232.php on line 7
27+
Exception on line 8
28+
29+
Notice: constant_def.inc in %sconstant_def.inc on line 3
30+
Exception in constant_def.inc on line 4
31+
32+
Notice: required.inc in %srequired.inc on line 3
33+
Exception in required.inc on line 4

Zend/tests/gh10232/constant_def.inc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
trigger_error(basename(__FILE__));
4+
$ex = new Exception();
5+
echo 'Exception in ', basename($ex->getFile()), ' on line ', $ex->getLine(), "\n";
6+
7+
require_once 'required.inc'; // The script of the same directory.
8+
9+
class ConstantDef
10+
{
11+
const VALUE = true;
12+
}

Zend/tests/gh10232/required.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
trigger_error(basename(__FILE__));
4+
$ex = new Exception();
5+
echo 'Exception in ', basename($ex->getFile()), ' on line ', $ex->getLine(), "\n";

Zend/tests/gh7771_3.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ spl_autoload_register(function($class) use ($classlist) {
1212
var_dump(D::HW);
1313
?>
1414
--EXPECTF--
15-
Fatal error: Constant expression contains invalid operations in %sgh7771_3.php(7) : eval()'d code(1) : eval()'d code on line 1
15+
Fatal error: Constant expression contains invalid operations in %sgh7771_3.php(7) : eval()'d code on line 1
1616

Zend/zend_execute_API.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,9 +1205,15 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, zend_string *
12051205
autoload_name = zend_string_copy(name);
12061206
}
12071207

1208+
zend_string *previous_filename = EG(filename_override);
1209+
zend_long previous_lineno = EG(lineno_override);
1210+
EG(filename_override) = NULL;
1211+
EG(lineno_override) = -1;
12081212
zend_exception_save();
12091213
ce = zend_autoload(autoload_name, lc_name);
12101214
zend_exception_restore();
1215+
EG(filename_override) = previous_filename;
1216+
EG(lineno_override) = previous_lineno;
12111217

12121218
zend_string_release_ex(autoload_name, 0);
12131219
zend_hash_del(EG(in_autoload), lc_name);

0 commit comments

Comments
 (0)