Skip to content

[PHP] Return type changed in PHP >= 8-0. Fluent setters now return static.#9431

Open
DamImpr wants to merge 1 commit into
apache:masterfrom
DamImpr:fluent_setter_static_from_php_80
Open

[PHP] Return type changed in PHP >= 8-0. Fluent setters now return static.#9431
DamImpr wants to merge 1 commit into
apache:masterfrom
DamImpr:fluent_setter_static_from_php_80

Conversation

@DamImpr

@DamImpr DamImpr commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

From PHP version 8.0 onwards, the "static" return type has been adopted for fluent setters. In the "Generate Code" menu in NetBeans, no return type was assigned when fluent setters were created. This PR ensures that fluent setters, when used in a project configured with PHP version >= 8.0, correctly have the "static" return type.

@DamImpr DamImpr changed the title [PHP] Return type changed in PHP >= 8. Fluent setters now return static. [PHP] Return type changed in PHP >= 8-0. Fluent setters now return static. Jun 5, 2026
@mbien mbien added the PHP [ci] enable extra PHP tests (php/php.editor) label Jun 6, 2026

@matthiasblaesing matthiasblaesing left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In general makes sense to me. I left an inline comment, regarding an unintentional change?!

@tmysik could you please have a look?

@tmysik

tmysik commented Jun 9, 2026

Copy link
Copy Markdown
Member

@matthiasblaesing I will look into it tomorrow.

@apache apache locked and limited conversation to collaborators Jun 9, 2026
@apache apache unlocked this conversation Jun 9, 2026

@tmysik tmysik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall, it looks good to me, thank you for your work.

Just as requested in one of my comments, please add a link to the official PHP documentation describing this feature. This is always useful. Once we verify it, we are good to merge (once my comments are fixed too).

Thank you!

@DamImpr

DamImpr commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

thank you @tmysik
I’ll check the two test methods that failed, have a look at your comments, and re-squash the commits. I’ll tag both of you in the conversation once I’ve got the actions running again

thank you

@DamImpr DamImpr requested a review from tmysik June 14, 2026 20:06
@DamImpr DamImpr force-pushed the fluent_setter_static_from_php_80 branch from b4c1031 to e812432 Compare June 14, 2026 20:11
@DamImpr

DamImpr commented Jun 14, 2026

Copy link
Copy Markdown
Contributor Author

@matthiasblaesing @tmysik
I’ve fixed the two test cases that were failing, made the changes requested by @tmysik, and squashed the commits.
If there’s anything else that needs doing, just let me know 💪

@tmysik

tmysik commented Jun 15, 2026

Copy link
Copy Markdown
Member

@DamImpr, thanks for your changes, but see my comment above - we need the official PHP documentation of this feature/change so we are correct from the implementation/support point of view. Thank you for understanding.

CC @matthiasblaesing

@DamImpr

DamImpr commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

@tmysik Let me have a look in the official PHP documentation, in the section on the static type, to see if I can find what you need. I'll let you know

@tmysik tmysik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Doc: https://wiki.php.net/rfc/static_return_type

Approving, thank you for your work.

@tmysik

tmysik commented Jun 16, 2026

Copy link
Copy Markdown
Member

@DamImpr

BTW, should we consider adding also self? What do you think? 🤔

@DamImpr

DamImpr commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

@DamImpr

BTW, should we consider adding also self? What do you think? 🤔

@tmysik In my opinion, the static return type is more appropriate than self in this case.
By creating the fluent setter with return $this, the return type will always be the actual type being called, precisely the reason why static was introduced as a return type.

@tmysik

tmysik commented Jun 16, 2026

Copy link
Copy Markdown
Member

@DamImpr
BTW, should we consider adding also self? What do you think? 🤔

@tmysik In my opinion, the static return type is more appropriate than self in this case. By creating the fluent setter with return $this, the return type will always be the actual type being called, precisely the reason why static was introduced as a return type.

I get it and agree. I meant more - should we return self for older PHP versions? Just an idea, maybe not so important or useful at all. Sorry for not being clear from the beginning.

@DamImpr

DamImpr commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

@DamImpr
BTW, should we consider adding also self? What do you think? 🤔

@tmysik In my opinion, the static return type is more appropriate than self in this case. By creating the fluent setter with return $this, the return type will always be the actual type being called, precisely the reason why static was introduced as a return type.

I get it and agree. I meant more - should we return self for older PHP versions? Just an idea, maybe not so important or useful at all. Sorry for not being clear from the beginning.

@tmysik It certainly wouldn’t be a bad idea to add the logic that fluent setters in PHP 7.[0-4] have self as their return type. After all, the Symfony framework used to write fluent setters with self as the return type when creating entities, before PHP 8.0 was released (it has now, of course, replaced self with static)

I’ll take the opportunity presented by this PR to do so. I’ll push the change as soon as possible.

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

Labels

PHP [ci] enable extra PHP tests (php/php.editor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants