Skip to content

Commit 8a7d79d

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Temporary reset filename and lineno override before autoload
2 parents 3f0b204 + 5899cab commit 8a7d79d

File tree

5 files changed

+57
-1
lines changed

5 files changed

+57
-1
lines changed

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
@@ -1227,9 +1227,15 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, zend_string *
12271227
autoload_name = zend_string_copy(name);
12281228
}
12291229

1230+
zend_string *previous_filename = EG(filename_override);
1231+
zend_long previous_lineno = EG(lineno_override);
1232+
EG(filename_override) = NULL;
1233+
EG(lineno_override) = -1;
12301234
zend_exception_save();
12311235
ce = zend_autoload(autoload_name, lc_name);
12321236
zend_exception_restore();
1237+
EG(filename_override) = previous_filename;
1238+
EG(lineno_override) = previous_lineno;
12331239

12341240
zend_string_release_ex(autoload_name, 0);
12351241
zend_hash_del(EG(in_autoload), lc_name);

0 commit comments

Comments
 (0)