Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ext/reflection: make getDocComment() methods return empty string instead of false #18928

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

Closed
Girgias wants to merge 1 commit into php:master from Girgias:reflection-doc-comment

Conversation

Copy link
Member

@Girgias Girgias commented Jun 24, 2025

Returning false is just annoying for non-existent doc comment

Found this while seeing the impact of #18879 on Symfony's test suite.
And discussing with @nicolas-grekas it seems to just make more sense to fix PHP.

...ead of false
Returning false is just annoying for non-existent doc comment
@Girgias Girgias force-pushed the reflection-doc-comment branch from b08f4d1 to d03aa48 Compare June 24, 2025 15:30
Copy link
Member

DanielEScherzer commented Jun 24, 2025
edited
Loading

Hmm, so I'm torn
On the one hand, indicating no comment with an empty string suggests that maybe there is a comment but it was just empty, while false makes it clear there was absolutely no comment
On the other hand, https://3v4l.org/fJBKT suggests that you cannot have an empty comment, the /** and */ are part of the comment that is returned, so an empty string can't really indicate an empty comment
But this would also break code that checks the return without just if ($ref->getDocComment()), e.g. if ($ref->getDocComment() !== false)

I only needed to go to the second page of the GitHub search results for "->getDocComment()" lang:php to find such code:
https://github.com/salient-labs/toolkit/blob/ee9034a67f1d90201c38f304638fac8ea8a198f6/src/Toolkit/PHPDoc/PHPDocUtil.php#L55

At the very least, this should probably have a discussion on the internals list

I also saw some existing code that works around the false return, using ?: or a (string) cast - is that not possible for Symfony?

kocsismate, donquixote, and iluuu1994 reacted with thumbs up emoji

Copy link
Member Author

Girgias commented Jun 25, 2025

Hmm, so I'm torn On the one hand, indicating no comment with an empty string suggests that maybe there is a comment but it was just empty, while false makes it clear there was absolutely no comment On the other hand, https://3v4l.org/fJBKT suggests that you cannot have an empty comment, the /** and */ are part of the comment that is returned, so an empty string can't really indicate an empty comment But this would also break code that checks the return without just if ($ref->getDocComment()), e.g. if ($ref->getDocComment() !== false)

I only needed to go to the second page of the GitHub search results for "->getDocComment()" lang:php to find such code: https://github.com/salient-labs/toolkit/blob/ee9034a67f1d90201c38f304638fac8ea8a198f6/src/Toolkit/PHPDoc/PHPDocUtil.php#L55

At the very least, this should probably have a discussion on the internals list

I also saw some existing code that works around the false return, using ?: or a (string) cast - is that not possible for Symfony?

It is possible, but I'm not sure that there is a big point in it. But I will raise this on internals.

Copy link
Contributor

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with me to restrict this type, but breaks subclassing, due to the return type changing

Copy link
Member Author

Girgias commented Jun 25, 2025

Fine with me to restrict this type, but breaks subclassing, due to the return type changing

The return type is mark as tentative, so you'd "just" get a warning. Which is also why I want this to land prior to PHP 9

Ocramius reacted with thumbs up emoji

Copy link
Member Author

Girgias commented Jul 31, 2025

Internals didn't think this was worthwhile: https://news-web.php.net/php.internals/127747

Ocramius reacted with confused emoji

@Girgias Girgias deleted the reflection-doc-comment branch July 31, 2025 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@kocsismate kocsismate Awaiting requested review from kocsismate kocsismate is a code owner

@DanielEScherzer DanielEScherzer Awaiting requested review from DanielEScherzer DanielEScherzer is a code owner

1 more reviewer

@Ocramius Ocramius Ocramius left review comments

Reviewers whose approvals may not affect merge requirements
Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /