Skip to content

gen_stub.php: Allowed the use of formats like @param array<> #18924

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SakiTakamachi
Copy link
Member

@SakiTakamachi SakiTakamachi commented Jun 24, 2025

This doesn’t change any output, but it makes it easier to provide hints for PHPStan or IDEs.

@SakiTakamachi SakiTakamachi marked this pull request as ready for review June 24, 2025 06:58
@DanielEScherzer
Copy link
Member

Do you have an example where this would be used?

@SakiTakamachi
Copy link
Member Author

@DanielEScherzer

No, it doesn’t seem necessary for the current code.
I noticed this while creating a prototype for a method that might be proposed as a new addition.
Do you think it’s better not to add it yet?

@DanielEScherzer
Copy link
Member

I was just wondering what that prototype was, in case it could be accomplished with the existing support

@SakiTakamachi
Copy link
Member Author

@DanielEScherzer

Ah, I see.
It’s array<mixed, Number|string|int>.

@DanielEScherzer
Copy link
Member

That is definitely already possible for return values, e.g.

* @return array<int|string, int|string|array>

And from what I can see the @param and @return parsing have the same logic

What error are you getting if you try @param array<mixed, Number|string|int> $foo now?
What about @param array<string|int, Number|string|int> $foo ?

@SakiTakamachi
Copy link
Member Author

SakiTakamachi commented Jun 24, 2025

@DanielEScherzer

The exception I am encountering is this one:

throw new Exception("@$this->name doesn't contain a variable name or has an invalid format \"$value\"");

And from what I can see the @param and @return parsing have the same logic

No, different regular expressions are used for param and return.

edit: Sorry, that might not be correct ↑

edit2: Understood. This method is probably not used for return.

case 'param':

In param, if <> follows array, it fails to extract the variable name.

if ($this->name === "param") {

@DanielEScherzer
Copy link
Member

Ah, okay, so the type gets extracted, but not the name? Then this patch makes sense to me, but I'll leave final approval for @kocsismate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants