-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed as not planned
Labels
Description
Description
Hello!
There is so strange behavior of the code when using the generator inside the if branch.
The following code:
<?php
$condition = false;
$func = fn() => $condition ? yield from [] : new \ArrayIterator([1, 2, 3]);
$iterator = $func();
foreach ($iterator as $el) {
echo "$el\n";
}
Don't print any to the output.
It seems like yield
clause is executing anytime despite the code execution (code in example will never enter the if
branch).
So, this code should produce this output:
1
2
3
PHP Version
PHP 8.3.14
Operating System
Ubuntu 22.04