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.

Initial test cases

prevent the return type from being generated in the PHPDoc when it is a constructor.

prevent the return type from being generated in the PHPDoc when it is a constructor.

Removed the return type from the constructor in the list of methods to override

commit missing file

fix compare insensitive
@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?

Comment on lines +2335 to +2337
List<PhpElement> topLevelElements = new ArrayList<>(request.index.getTopLevelElements(prefix, aliasedNames, Trait.ALIAS));
topLevelElements.sort(Comparator.comparing(PhpElement::getName, String.CASE_INSENSITIVE_ORDER));
for (final PhpElement element : topLevelElements) {

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.

Is this intentionally here? This does not seem to be relevant for the declared intention of the PR 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.

Hi @matthiasblaesing
You’re right, it isn’t mentioned in the PR description.
It’s a change I made after development because two tests were failing when I ran tests on the php.editor.completion package, specifically testFunctionGuessingArrayReturnType_01 and testFunctionGuessingArrayReturnType_02.

In short, the return types did not have a deterministic order. For example, the method might return an array|string, which is valid in the language but differs from what the test method expected, namely string|array.
This change ensures a deterministic order, and the test suite no longer fails.

I’m not sure whether, given the project’s policies, this can be merged alongside the fix I’ve made. Please let me know if this is fine or if a separate PR is needed.
Thanks

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.

Ok, I don't see a problem in having the completion list deterministic and sorted is IMHO a good base.

@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
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.

4 participants