-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
Make ReflectionGenerator::getFunction()
legal after generator termination
#14167
Make ReflectionGenerator::getFunction()
legal after generator termination
#14167
Conversation
Draft while investigating the ASAN failures. Didn't catch them locally, due to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense
I'm not sure if this makes any benefits, but this is a behavior change and should go through RFC. Change to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The patch leads to crashes on few tests.
It's not possible to directly instantiate the Generator class [Zend/tests/generators/errors/generator_instantiate_error.phpt]
Try to instantiate all classes without arguments [Zend/tests/instantiate_all_classes.phpt]
Bug #64007 (There is an ability to create instance of Generator by hand) [ext/reflection/tests/bug64007.phpt]
d0afb9e
to
0852151
Compare
Now fixed, thank you. This was a regression after Ilija's review that I didn't catch locally, because the tests do not contain a |
I believe the addition of a new |
I wouldn't consider this as a self-contained change, because it is exposed to user (var_dump output). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should also adjust getExecutingFile
, which doesn't need to rely on execute_data
anymore.
This looks good to me otherwise. I don't think changes like these should require RFCs. Adding something to the debug output is barely a change. The technical aspects would be better evaluated by a technical committee than internals, but that proposal was rejected.
I've considered that, but I'm not sure how useful that is without The filename would also already be available via |
I think, it's better to allow than to throw when there's no technical reason. The function name is just a bit of a misnomer. But I don't care too much. |
At least While of course a single generator can’t execute in different files, it makes sense to me that |
@dstogov I don't think this change is significant enough to require a RFC and consensus is fine. I support this change, provides a bit more visibility. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this PR could provide an (in)direct way of solving #11591
But I'd have to check after merging if we can utilise your functionality.
This changes debug info output, but debug info output changes have happened before without requiring an RFC. At worst, some test cases would have to be adjusted so unless there's complaints I don't think this needs an RFC.
And I agree with Tim about the getExecutingLine()
/ getExecutingFile()
thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't object
830eee7
to
9cc2357
Compare
This PR break Symfony CI because it relies on a Creating a |
@alexandre-daubois Thanks for letting us know. What is the result of the test? Does |
Here is the update I proposed to the framework: https://github.com/symfony/symfony/pull/57191/files As you can see, the dump format has changed (which is fine). With this PR, instantiating a This is why I moved the call to |
…bois) This PR was merged into the 5.4 branch. Discussion ---------- [VarDumper] Fix generator dump on PHP 8.4 | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT From PHP 8.4, generators dump contains the generating function: php/php-src#14167. Also, creating a ReflectionGenerator on a closed generator is now permitted, which explains the update in `ReflectionCaster` to catch anything that may happen in `castReflectionGenerator()`. Commits ------- fc0dc0e [VarDumper] Fix generator dump on PHP 8.4
@alexandre-daubois Would an explicit |
It would be a nice addition for sure! Definitely a good idea, cleaner than checking for an exception. I think in the case of this Symfony class, it could help to refactor a bit but the patch I proposed actually works well. |
* reflection: Add `ReflectionGenerator::isClosed()` see #14167 (comment) * Fix test expectation * Drop `{{{` / `}}}` comments around `ReflectionGenerator::isClosed()`
Currently after termination, a
Generator
loses all its information, except for the return value (if any). This makes it hard to impossible to introspect where that return value is coming from, for example in debuggers.This PR adds an explicit
zend_function*
to thestruct _zend_generator
to allow the retrieval of the function even after termination. This new pointer allowsReflectionGenerator::getFunction()
to work correctly at all times. As a side-benefit I was able to add the function name to the__debugInfo()
, making it more easily available without going through Reflection, allowing users to distinguish different Generators at a glance.