[php-src] PR #22211: Fix GH-22168: Make phpdbg ignore unloaded catch classes
| From: | shamanzpua | Date: | Tue, 02 Jun 2026 18:26:37 +0000 |
| Subject: | [php-src] PR #22211: Fix GH-22168: Make phpdbg ignore unloaded catch classes | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-36278@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/22211
Author: shamanzpua
Fixes GH-22168
## Problem
When running under interactive phpdbg, phpdbg reports a bogus fatal error for
an exception that is actually caught if an earlier
catch block references a
class that does not exist and is not autoloaded:
```php
<?php declare(strict_types=1);
try {
throw new RuntimeException();
} catch (LibrarySpecificException) {
// Not autoloaded since it did not happen.
} catch (RuntimeException) {
echo "Caught it. 'handled' it\n";
}
```
php and phpdbg -qrr print the expected output:
```text
Caught it. 'handled' it
```
but interactive phpdbg reports:
```text
PHP Fatal error: During class fetch: Uncaught RuntimeException ...
```
## Cause
phpdbg_check_caught_ex() resolves catch block classes via
zend_fetch_class_by_name() with ZEND_FETCH_CLASS_NO_AUTOLOAD, but without
ZEND_FETCH_CLASS_SILENT.
This differs from the actual ZEND_CATCH opcode handler, which resolves catch
types with ZEND_FETCH_CLASS_SILENT.
If the earlier catch type does not exist, the non-silent class fetch reports an
error while the original exception is already active. This makes phpdbg report
the caught exception as uncaught.
## Fix
Add ZEND_FETCH_CLASS_SILENT to the phpdbg catch check, matching the behavior
of the ZEND_CATCH opcode handler.
A regression test was added in:
```text
sapi/phpdbg/tests/exceptions_004.phpt
```
## Tested
- Confirmed the issue with an A/B build
- Confirmed the fix makes interactive phpdbg print the expected output
- phpdbg test suite: 64 passed, 0 failed