-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Make ReflectionGenerator::getFunction()
legal after generator termination
#14167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TimWolla
merged 8 commits into
php:master
from
TimWolla:generator-get-function-after-end
May 21, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
47cbd1c
Make `ReflectionGenerator::getFunction()` legal after generator termi…
TimWolla 9acc1ed
Expose the generator function name via `Generator::__debugInfo()`
TimWolla e988e4d
Allow creating `ReflectionGenerator` after termination
TimWolla e4dfda5
Reorder `struct _zend_generator` to avoid a hole
TimWolla 61d252c
Adjust `ext/reflection/tests/028.phpt`
TimWolla 111e856
Fix Generator Closure collection
TimWolla 9cc2357
Add test to verify the Closure dies with the generator
TimWolla ba2cec2
NEWS / UPGRADING
TimWolla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
--TEST-- | ||
Generators expose the underlying function name in __debugInfo(). | ||
--FILE-- | ||
<?php | ||
|
||
function foo() { | ||
yield; | ||
} | ||
|
||
$gens = [ | ||
(new class() { | ||
function a() { | ||
yield from foo(); | ||
} | ||
})->a(), | ||
(function() { | ||
yield; | ||
})(), | ||
foo(), | ||
]; | ||
|
||
foreach ($gens as $gen) { | ||
echo "Before:", PHP_EOL; | ||
var_dump($gen); | ||
|
||
foreach ($gen as $dummy) { | ||
echo "Inside:", PHP_EOL; | ||
var_dump($gen); | ||
} | ||
|
||
echo "After:", PHP_EOL; | ||
|
||
var_dump($gen); | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Before: | ||
object(Generator)#%d (1) { | ||
["function"]=> | ||
string(%d) "class@anonymous%s::a" | ||
} | ||
Inside: | ||
object(Generator)#%d (1) { | ||
["function"]=> | ||
string(%d) "class@anonymous%s::a" | ||
} | ||
After: | ||
object(Generator)#%d (1) { | ||
["function"]=> | ||
string(%d) "class@anonymous%s::a" | ||
} | ||
Before: | ||
object(Generator)#%d (1) { | ||
["function"]=> | ||
string(%d) "{closure:%s:%d}" | ||
} | ||
Inside: | ||
object(Generator)#%d (1) { | ||
["function"]=> | ||
string(%d) "{closure:%s:%d}" | ||
} | ||
After: | ||
object(Generator)#%d (1) { | ||
["function"]=> | ||
string(%d) "{closure:%s:%d}" | ||
} | ||
Before: | ||
object(Generator)#%d (1) { | ||
["function"]=> | ||
string(3) "foo" | ||
} | ||
Inside: | ||
object(Generator)#%d (1) { | ||
["function"]=> | ||
string(3) "foo" | ||
} | ||
After: | ||
object(Generator)#%d (1) { | ||
["function"]=> | ||
string(3) "foo" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--TEST-- | ||
The Closure object of a generator is freed when the generator is freed. | ||
--FILE-- | ||
<?php | ||
|
||
$genFactory = function() { | ||
yield 1; | ||
yield 2; | ||
yield 3; | ||
}; | ||
|
||
$r = WeakReference::create($genFactory); | ||
$generator = $genFactory(); | ||
unset($genFactory); | ||
|
||
var_dump($r->get()); | ||
|
||
foreach ($generator as $value) var_dump($value); | ||
|
||
var_dump($r->get()); | ||
|
||
unset($generator); | ||
|
||
var_dump($r->get()); | ||
|
||
?> | ||
--EXPECTF-- | ||
object(Closure)#%d (3) { | ||
["name"]=> | ||
string(%d) "{closure:%s:%d}" | ||
["file"]=> | ||
string(%d) "%s" | ||
["line"]=> | ||
int(%d) | ||
} | ||
int(1) | ||
int(2) | ||
int(3) | ||
object(Closure)#%d (3) { | ||
["name"]=> | ||
string(%d) "{closure:%s:%d}" | ||
["file"]=> | ||
string(%d) "%s" | ||
["line"]=> | ||
int(%d) | ||
} | ||
NULL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.