View Issue Details

IDProjectCategoryView StatusLast Update
0002390XdebugUncategorizedpublic2026-01-22 16:01
Reporterfrozenbrain Assigned Toderick  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionno change required 
Product Version3.4.7 
Summary0002390: Exception not caught when iterating over a Generator variable with try-finally
Description

We've noticed unit tests failing after updating to PHP 8.4.15 because an exception was no longer caught when it should have been.
I am not sure what exactly causes the issue, but I've narrowed it down to the minimal reproducer provided below. I was not able to trim it down any further.

I was unable to reproduce the issue with PHP 8.4.14 or with XDebug disabled which leads me to believe that this is a bug in XDebug.

Steps To Reproduce

Run the following script with XDebug enabled (XDEBUG_MODE=debug or coverage):

<?php

try {
    test();
} catch (Throwable $t) {
    echo 'catch ' . $t->getMessage();
}

function test(): void
{
    $values = generate();

    foreach ($values as $ignored) {
        throw new LogicException('test');
    }
}

function generate(): Generator
{
    try {
        yield 1;
    } finally {
        echo ''; // noop for debugging
    }
}

Expected result: The script should output catch test
Actual result: Fatal error: Uncaught LogicException: test

One thing I noticed while debugging is that the stack trace changes after stepping over the throw instruction: The line number of the bottom-most stack frame changes from 4 to 14. In my actual code this is much more obvious, as the new stack frame points to a completely unrelated line of code that was not even executed. It looks like the line number of the throw instruction is moved to the stack frame below.

Additional Information

Tested with PHP running in Docker 29.0.2.

PHP 8.4.15 (cli) (built: Nov 20 2025 19:53:04) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.4.15, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.15, Copyright (c), by Zend Technologies
    with Xdebug v3.4.7, Copyright (c) 2002-2025, by Derick Rethans
TagsNo tags attached.
Operating SystemFedora 42
PHP Version8.4.10-8.4.19

Activities

frozenbrain

2026-01-12 13:16

reporter   ~0007439

According to a Git Bisect I ran between PHP 8.4.14 an 8.4.15, this is the commit that introduced the issue: https://github.com/php/php-src/commit/12920370e1806584a558799098075510a5ab3444
However, I cannot assess whether this is an error in PHP that is only brought to the surface by XDebug, or whether the bug lies in XDebug.

And just for reference this also affects PHP 8.4.16 with XDebug 3.5.0.

frozenbrain

2026-01-12 13:58

reporter   ~0007440

I just noticed that this exact issue was apparently fixed in PHP 8.5.2 (not yet released): https://github.com/php/php-src/pull/20716
The sample code in https://github.com/php/php-src/issues/20714 looks almost identical to mine, though for me it also only breaks with XDebug enabled for some reason.

derick

2026-01-15 12:46

administrator   ~0007448

@frozenbrain — thanks for checking that. I don't know what the reason is either, but I think we probably should wait to see if 8.5.2 fixes this. It should come out today.

frozenbrain

2026-01-19 06:26

reporter   ~0007450

No longer reproducible on either 8.4.17 or 8.5.2, so this seems to be fixed.
Sorry for blaming XDebug prematurely.

derick

2026-01-22 16:01

administrator   ~0007452

This turned out to be a bug in PHP then, thanks for double checking!

Issue History

Date Modified Username Field Change
2025-11-26 10:36 frozenbrain New Issue
2026-01-12 13:16 frozenbrain Note Added: 0007439
2026-01-12 13:58 frozenbrain Note Added: 0007440
2026-01-15 12:46 derick Note Added: 0007448
2026-01-19 06:26 frozenbrain Note Added: 0007450
2026-01-22 16:01 derick Assigned To => derick
2026-01-22 16:01 derick Status new => resolved
2026-01-22 16:01 derick Resolution open => no change required
2026-01-22 16:01 derick Note Added: 0007452