Skip to content

[PHP] keyword return omitted in a constructor override - #9604

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

[PHP] keyword return omitted in a constructor override#9604
DamImpr wants to merge 1 commit into
apache:masterfrom
DamImpr:php_construct_without_return

Conversation

@DamImpr

@DamImpr DamImpr commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

In connection with the fix I made in PR 9395, which correctly resolved the issue with the return type in the constructor, IDE still generates return parent::__construct(); when overriding a parent constructor. .

Although the return statement in the constructor does not actually cause a runtime error, I’d like to explain why I believe it is still incorrect to include it, and why I am submitting this PR:

The RFC “Ensure correct signatures of magic methods” explicitly states that

__construct() and __destruct() remain unchanged and continue to permit no declared return type — not even void — because, as the rationale states: almost all languages, including PHP, do not have the concept of constructors and destructors that “return” anything upon completion of their execution.

This is therefore the officially accepted source which establishes, at the level of the PHP language RFC, the principle that, conceptually, a constructor must not return anything.

… a constructor.

Removed the return type from the constructor in the list of methods to override
@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 Sep 7, 2026
@apache apache locked and limited conversation to collaborators Sep 7, 2026
@apache apache unlocked this conversation Sep 7, 2026
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.

2 participants