Skip to content

Fix GH-10232 autoload during constant resolution. #13313

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
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.2.17

- Core:
. Fixed bug GH-10232 (if autoloading occurs during constant resolution
filename and lineno are identified incorrectly). (ranvis)

- Curl:
. Fix failing tests due to string changes in libcurl 8.6.0. (Ayesh)

Expand Down
33 changes: 33 additions & 0 deletions Zend/tests/gh10232.phpt
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions Zend/tests/gh10232/constant_def.inc
Original file line number Diff line number Diff line change
@@ -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;
}
5 changes: 5 additions & 0 deletions Zend/tests/gh10232/required.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

trigger_error(basename(__FILE__));
$ex = new Exception();
echo 'Exception in ', basename($ex->getFile()), ' on line ', $ex->getLine(), "\n";
2 changes: 1 addition & 1 deletion Zend/tests/gh7771_3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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

6 changes: 6 additions & 0 deletions Zend/zend_execute_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down