[php-src] Issue #21190: get_declared_interfaces() does not include interfaces extending from other interfaces if script returns early

[email protected] (tiberiusteng)
Newsgroups php.bugs
Message-ID <pgVaNPDt2oHtfZbVMaNP2ymR088BgNhqRLRwCPyqqh0@main.internal.php.net>
Issue: https://github.com/php/php-src/issues/21190
Author: tiberiusteng

### Description

The following code:

```php
<?php
print_r(get_declared_interfaces());
print_r(get_declared_classes());
if (interface_exists('a')) {
    return;
}

interface a {}
interface b extends a {}

class c {}
class d extends c {}
```

Only `a` appear in `get_declared_interfaces()`, both `c` and `d` appear in `get_declared_classes()`, perhaps they should be consistent?

We were trying to use `if (interface_exists('a')) exit;` to prevent redeclaring an interface (upgrading legacy code from require_once to SPL autoload), but discovered that adding `interface_exists()` to old code would prevent them being loaded even when there are no new autoloaded version registered.

Also at first we are assuming `get_declared_interfaces()`, `get_declared_classes()` won't include code after them, but seems this is expected behavior.

### PHP Version

```plain
PHP 8.5.2 (cli) (built: Jan 13 2026 21:40:53) (NTS)
Copyright (c) The PHP Group
Built by Homebrew
Zend Engine v4.5.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.2, Copyright (c), by Zend Technologies
```

### Operating System

_No response_
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.