====== PHP RFC: Deprecate returning values from __construct() and __destruct() ======
* Version: 1.0
* Date: 2026-05-08
* Author: Tim Düsterhus, timwolla@php.net
* Status: Under Discussion
* Implementation: https://github.com/php/php-src/pull/21982
===== Introduction =====
A class’ constructor and destructor (“Lifecycle Functions”) are special in that they are not meant to be used like regular methods and called manually. Observing the return value during intended use is not possible.
To that effect they are already restricted from declaring any return type at all, including declaring a return type of void. It however is nevertheless legal to return a value from these methods, which can be confusing, particularly when returning a separate valid object instance from __construct().
===== Proposal =====
Deprecate returning values from __construct() and __destruct(). Using return …; shall emit a compile-time deprecation. Using return; without an expression to “skip” over the remaining logic shall remain legal. Starting with the next major version, returning a value shall emit a compile-time error.
This deprecation is in line with the existing error when returning a value from a void function:
It will remain legal to manually call __construct() and __destruct(), for example to call a parent constructor or destructor - or to initialize a [[lazy-objects|lazy object]].
===== Backward Incompatible Changes =====
The deprecation itself is not a backwards incompatible change. When it is turned into an error, code that returns values will stop working. The justification is provided in the introduction.
===== Proposed PHP Version(s) =====
Deprecation in the next PHP version (8.6). Removal in the first major after that.
===== RFC Impact =====
==== To the Ecosystem ====
Static analyzers and IDEs will want to point out:
* Cases where a value is returned from a constructor or destructor.
* Cases where the return value of a constructor or destructor is used.
==== To Existing Extensions ====
None.
==== To SAPIs ====
None.
===== Open Issues =====
None.
===== Future Scope =====
Similar arguments apply to __clone(). However in that case specifying an explicit return type of void is legal. __clone() will therefore implicitly be handled if / when magic methods are required to specify accurate return (and parameter) types.
===== Voting Choices =====
Primary Vote requiring a 2/3 majority to accept the RFC:
* Yes
* No
* Abstain
===== Patches and Tests =====
https://github.com/php/php-src/pull/21982
===== Implementation =====
After the RFC is implemented, this section should contain:
- the version(s) it was merged into
- a link to the git commit(s)
- a link to the PHP manual entry for the feature
===== References =====
* Mailing List Discussion of making new emit an error if a value is returned: https://news-web.php.net/php.internals/129980
* An earlier, similar, RFC: [[make_ctor_ret_void|PHP RFC: Make constructors and destructors return void]]
* Discussion of this RFC: https://news-web.php.net/php.internals/130808
===== Rejected Features =====
None.
===== Changelog =====
* 2026-05-08: Initial version