Skip to content

[PHP] FIXES #9171 Return type not added to constructor override#9234

Open
DamImpr wants to merge 1 commit intoapache:masterfrom
DamImpr:fix-php-override-constructor
Open

[PHP] FIXES #9171 Return type not added to constructor override#9234
DamImpr wants to merge 1 commit intoapache:masterfrom
DamImpr:fix-php-override-constructor

Conversation

@DamImpr
Copy link

@DamImpr DamImpr commented Feb 26, 2026

As reported in issue #9171 adding the return type to the constructor in a PHP project caused a conflict with the ‘override methods’ feature, making the code incompatible with PHP inheritance rules.

This PR removes the return type from the constructor, restoring compatibility with PHP conventions and resolving the reported bug.
Effect: the constructor can now be correctly overridden in child classes, as expected by the language.

@geek998
Copy link

geek998 commented Feb 26, 2026

Good job! very useful

@mbien mbien added PHP [ci] enable extra PHP tests (php/php.editor) ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) labels Feb 26, 2026
@apache apache locked and limited conversation to collaborators Feb 26, 2026
@apache apache unlocked this conversation Feb 26, 2026
@matthiasblaesing
Copy link
Contributor

@DamImpr thanks for taking are and working on this. The CI/CD run showed errors. The execution fails in the PHPCodeCompletionNb5370Test. To be precise the testInterface one. I ran tests locally and that is the only one failing now.

From reading the code the problem is, that testInterface is detected as a possible constructor for TestInterface. Given the intention of the test, I think the method name is unfortunate and changing it seems sensible.

The tests can be run from the IDE by opening the context menu of the project and choose Test there. Be warned: The PHP test suite is extensive. The runs on github take in the range of 45-60 minutes. You can run individual test files be invoking "Test file" on the corresponding java file or the context menu when the file is open. You can also run individual tests be using "Run focused test method from the context menu when you click inside the method body.

It would be good if you could add a testcase for the expected behavior. PHPCodeCompletionGH8644Test could be an inspiration. The general idea is mostly:

  1. Create the test PHP file
  2. Add the java side which basicly describes which file to use as basis and which line to check for completion
  3. Run the test once. This will generate the "golden" file. You need to check whether that file holds the right information. If so, you commit it together the PHP file, the java unittest file. This triplet will act as regression test.

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

Labels

ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) PHP [ci] enable extra PHP tests (php/php.editor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[PHP] 'Generate override' feature assigns the return type in the constructor

4 participants