View Issue Details

IDProjectCategoryView StatusLast Update
0002390XdebugUncategorizedpublic2025-11-26 10:36
Reporterfrozenbrain Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
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

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
2025-11-26 10:36 frozenbrain New Issue