[php-src] Issue #10232: Weird behaviour when a file is autoloaded in assignment of a constant
| From: | fasterforward | Date: | Thu, 05 Jan 2023 13:41:16 +0000 |
| Subject: | [php-src] Issue #10232: Weird behaviour when a file is autoloaded in assignment of a constant | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-243346@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/10232
Author: fasterforward
### Description
The following files:
_test.php_
```php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
class Loader
{
public function __construct()
{
spl_autoload_register([$this, 'include'], true);
}
public function include()
{
require 'test/constant.php';
}
}
new Loader();
class B
{
public const A = constant::TEST;
}
new B();
echo 'here';
```
_test/constant.php_
```php
<?php
declare(strict_types=1);
require_once 'required.php';
class constant
{
public const TEST = 'test';
}
```
_test/required..php_
```php
<?php
```
Resulted in this output:
```
Warning: require_once(required.php): Failed to open stream: No such file or directory in
/mnt/fasterforward/web01/elements/src/httpdocs/test/test.php on line 21 Call Stack: 0.0183 365472 1.
{main}() /mnt/fasterforward/web01/elements/src/httpdocs/test/test.php:0 0.1607 397352 2.
Loader->include('constant')
/mnt/fasterforward/web01/elements/src/httpdocs/test/test.php:24 0.1611 397752 3.
require_once('/mnt/fasterforward/web01/elements/src/httpdocs/test/test.php')
/mnt/fasterforward/web01/elements/src/httpdocs/test/test.php:11 Fatal error: Uncaught Error: Failed
opening required 'required.php'
(include_path='.:/usr/share/pear:/usr/share/php:/usr/share/pear:/usr/share/php') in
/mnt/fasterforward/web01/elements/src/httpdocs/test/test.php on line 21 Error: Failed opening
required 'required.php'
(include_path='.:/usr/share/pear:/usr/share/php:/usr/share/pear:/usr/share/php') in
/mnt/fasterforward/web01/elements/src/httpdocs/test/test.php on line 21 Call Stack: 0.0183 365472 1.
{main}() /mnt/fasterforward/web01/elements/src/httpdocs/test/test.php:0 0.1607 397352 2.
Loader->include('constant')
/mnt/fasterforward/web01/elements/src/httpdocs/test/test.php:24 0.1611 397752 3.
require_once('/mnt/fasterforward/web01/elements/src/httpdocs/test/test.php')
/mnt/fasterforward/web01/elements/src/httpdocs/test/test.php:11
```
But I expected this output instead:
```
here
```
For some reason in when a file is autoloaded in assignment of a constant, the requires there do not
get checked based on the location of that file.
When I put the autoloader outside of a class, require the file directly or specify
constant as a type instead it works fine
In PHP 8.1.8 and PHP 7.4.30 with very simular php.ini's it works fine and the file gets
required properly.
I thought it might be opcache but when I disable it the same problem happens.
### PHP Version
PHP 8.2
### Operating System
Red Hat Enterprise Linux release 8.7