[php-src] Issue #21106: Missing trait is E_ERROR but missing extends/implements is Exception when autoloaded?
| From: | kkmuffme | Date: | Sun, 01 Feb 2026 05:35:34 +0000 |
| Subject: | [php-src] Issue #21106: Missing trait is E_ERROR but missing extends/implements is Exception when autoloaded? | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-251638@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/21106
Author: kkmuffme
### Description
The following code:
```php
<?php
spl_autoload_register( function ( $class_name ) {
if ( $class_name === 'Foo' ) {
require __DIR__ . '/foo.php';
}
} );
try {
class_exists( Foo::class );
} catch ( Throwable $e ) {
echo 'catch' . PHP_EOL;
}
```
foo.php
```
class Foo {
use Bar;
}
```
Resulted in this output:
```
Trait "Bar" not found
```
But I expected this output instead:
```
catch
```
Change foo.php to
```
class Foo extends Bar {}
```
and you will get the expected output. It's not consistent/illogical that traits behave
differently in this regard?
### PHP Version
```plain
PHP 8.5
```
### Operating System
_No response_