1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Temporary reset filename and lineno override before autoload

Closes GH-10232
Closes GH-13313
This commit is contained in:
SATO Kentaro
2024-02-17 00:23:12 +09:00
committed by Ilija Tovilo
parent 7d3d8de1f3
commit f8b9030b4e
6 changed files with 59 additions and 1 deletions

2
NEWS
View File

@@ -12,6 +12,8 @@ PHP NEWS
. Fixed bug GH-14003 (Broken cleanup of unfinished calls with callable convert
parameters). (ilutov)
. Fixed bug GH-14013 (Erroneous dnl appended in configure). (Peter Kokot)
. Fixed bug GH-10232 (If autoloading occurs during constant resolution
filename and lineno are identified incorrectly). (ranvis)
- Fibers:
. Fixed bug GH-13903 (ASAN false positive underflow when executing copy()).

33
Zend/tests/gh10232.phpt Normal file
View File

@@ -0,0 +1,33 @@
--TEST--
GH-10232 (Weird behaviour when a file is autoloaded in assignment of a constant)
--FILE--
<?php
set_include_path('gh10232-nonexistent') or exit(1);
chdir(__DIR__) or exit(1);
spl_autoload_register(function () {
trigger_error(__LINE__);
$ex = new Exception();
echo 'Exception on line ', $ex->getLine(), "\n";
require_once __DIR__ . '/gh10232/constant_def.inc';
}, true);
class ConstantRef
{
public const VALUE = ConstantDef::VALUE;
}
ConstantRef::VALUE;
?>
--EXPECTF--
Notice: 7 in %sgh10232.php on line 7
Exception on line 8
Notice: constant_def.inc in %sconstant_def.inc on line 3
Exception in constant_def.inc on line 4
Notice: required.inc in %srequired.inc on line 3
Exception in required.inc on line 4

View File

@@ -0,0 +1,12 @@
<?php
trigger_error(basename(__FILE__));
$ex = new Exception();
echo 'Exception in ', basename($ex->getFile()), ' on line ', $ex->getLine(), "\n";
require_once 'required.inc'; // The script of the same directory.
class ConstantDef
{
const VALUE = true;
}

View File

@@ -0,0 +1,5 @@
<?php
trigger_error(basename(__FILE__));
$ex = new Exception();
echo 'Exception in ', basename($ex->getFile()), ' on line ', $ex->getLine(), "\n";

View File

@@ -12,5 +12,5 @@ spl_autoload_register(function($class) use ($classlist) {
var_dump(D::HW);
?>
--EXPECTF--
Fatal error: Constant expression contains invalid operations in %sgh7771_3.php(7) : eval()'d code(1) : eval()'d code on line 1
Fatal error: Constant expression contains invalid operations in %sgh7771_3.php(7) : eval()'d code on line 1

View File

@@ -1205,9 +1205,15 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, zend_string *
autoload_name = zend_string_copy(name);
}
zend_string *previous_filename = EG(filename_override);
zend_long previous_lineno = EG(lineno_override);
EG(filename_override) = NULL;
EG(lineno_override) = -1;
zend_exception_save();
ce = zend_autoload(autoload_name, lc_name);
zend_exception_restore();
EG(filename_override) = previous_filename;
EG(lineno_override) = previous_lineno;
zend_string_release_ex(autoload_name, 0);
zend_hash_del(EG(in_autoload), lc_name);