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
}

private String getReturnType() {
if (cgsInfo.isFluentSetter() && cgsInfo.getPhpVersion().hasStaticReturnType()) {

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.

In order to use this newly added API method, you need to update the dependency version (once it is increased).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think I've quite got it. I've changed the version code in the "hasStaticReturnType" method.
Is that enough?

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.

Well, this was already discussed with @neilcsmith-net and currently, we don't version our APIs on every change (basically, no API version change in the development cycle). So, what exact version should be set in the Javadoc, I don't know. Neil, could you advise, please? Perhaps the current version + 1?

@DamImpr how this is supposed to work if we version every API change:

  • update/change the code of the API module (php.api.phpmodule here)
  • because of this change, increase the specification version of this module (e.g. 3.107 -> 3.108)
  • you want to use this newly added code in the PHP editor, so
  • update the dependency version in php.editor module to the latest one: 3.108
  • now, the newly added code is visible also in the PHP editor

Hopefully, it is more clear now.

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.

The current version in master is fine IMO. It is already ahead of NB30.

}

private String getReturnType() {
if (cgsInfo.isFluentSetter() && cgsInfo.getPhpVersion().hasStaticReturnType()) {

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.

Please, provide a link with documentation of this change. Does it mean that every fluent getter in PHP 8+ is static? Or am I wrong?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Exactly! I don’t know where to find a link to the documentation right now, but fluent setters always return an instance of the object itself. What’s more, the ‘insert code’ feature already ensured that fluent setters returned $this; all I added was the return type, which had previously been omitted in the case of fluent setters.

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.

@DamImpr, I am afraid that without official documentation of this change, we cannot merge this PR, sorry. We need to stay correct and as I wrote, it seems to me that with this change, every fluent setter would become a static one. And that is quite unexpected, no?

@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

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