# RFC: Deprecate returning values from __construct() and __destruct()

- Status: Implemented (PHP 8.6)
- Authors: Tim Düsterhus, timwolla@php.net
- Date: 2026-05-08
- Version: 1.0
- Implementation: https://github.com/php/php-src/pull/21982
- Original: https://wiki.php.net/rfc/deprecate-return-value-from-construct
- Page: https://externals.io/rfc/deprecate-return-value-from-construct
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

## Votes

### Deprecate returning values from __construct() and __destruct()? (closed)

Yes: 39 · No: 0 · Abstain: 0

Voters: alcaeus (Yes), alec (Yes), alexandredaubois (Yes), ayesh (Yes), brzuchal (Yes), crell (Yes), dams (Yes), daniels (Yes), dharman (Yes), dragoonis (Yes), duncan3dc (Yes), dunglas (Yes), enorris (Yes), galvao (Yes), girgias (Yes), heiglandreas (Yes), iliaa (Yes), ilutov (Yes), jordikroon (Yes), josh (Yes), kalle (Yes), kocsismate (Yes), levim (Yes), marandall (Yes), mauricio (Yes), mbeccati (Yes), ocramius (Yes), pmjones (Yes), ramsey (Yes), rasmus (Yes), sebastian (Yes), sergey (Yes), shivam (Yes), theodorejb (Yes), thorstenr (Yes), timwolla (Yes), trowski (Yes), weierophinney (Yes), weilindu (Yes)

## Discussions on the mailing list

- [\[IDEA for RFC\] let the "new" operator fail when the __construct() function returns a value.](https://externals.io/message/129980.md) — started on 2026-02-02, 32 messages
- [\[RFC\] Deprecate returning values from __construct() and __destruct()](https://externals.io/message/130808.md) — started on 2026-05-08, 9 messages
- [\[VOTE\] Deprecate returning values from __construct() and __destruct()](https://externals.io/message/131272.md) — started on 2026-06-15, 6 messages
- [\[PRE-RFC\] Deprecate returning from a finally block](https://externals.io/message/131393.md) — started on 2026-06-18, 10 messages

---

## 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. Since Generators effectively return a new `Generator` object, making `__construct()` and `__destruct()` a Generator shall also be deprecated. Starting with the next major version, returning a value shall emit a compile-time error.

```php
<?php
 
class Foo
{
	public function __construct()
	{
		return 123; // Deprecated: Returning a value from a constructor is deprecated in test.php on line 6
	}
 
	public function __destruct()
	{
		return 123; // Deprecated: Returning a value from a constructor is deprecated in test.php on line 12
	}
}
 
class Bar
{
	public function __construct()
	{
		if (random_int(0, 1)) {
			return; // Skipping the rest of the logic remains legal.
		}
 
		echo "Constructing", PHP_EOL;
	}
}
 
class Baz
{
	public function __construct()
	{
		yield 123; // Deprecated: Making a constructor a Generator is deprecated in test.php on line 30
	}
 
	public function __destruct()
	{
		yield 123; // Deprecated: Making a destructor a Generator is deprecated in test.php on line 35
	}
}
```

This deprecation is in line with the existing error when returning a value from a `void` function:

```php
<?php
 
function void_function(): void
{
	return 123; // Fatal error: A void function must not return a value in test.php on line 5
}
```

It will remain legal to manually call `__construct()` and `__destruct()`, for example to call a parent constructor or destructor - or to initialize a [lazy object](https://externals.io/rfc/lazy-objects).

## 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 `yield` is used in a constructor or destructor.
- Cases where the return value of a constructor or destructor is used.

An [analysis of the top 4000 composer packages run by Juliette Reinders Folmer with PHP\_CodeSniffer](https://gist.github.com/jrfnl/6782310676b7ff5942f97873a71552ea) revealed a total of 77 return statements with a value across 59 files and 36 packages. 2 of the return statements were inside `__destruct()`. 21 were of the form `return $this;`. One returned the value of a static property containing a non-`$this` object.

This indicates that albeit rare, there appears to be some misunderstanding of how constructors and destructors work in PHP that can be cleared up by deprecating this behavior.

### 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:

**Vote: Deprecate returning values from \_\_construct() and \_\_destruct()?** — Yes: 39 · No: 0 · Abstain: 0 (closed)

## Patches and Tests

<https://github.com/php/php-src/pull/21982>

## Implementation

- <https://github.com/php/php-src/commit/18d783719d58420fa7f333175830fcf40c916bea>

## 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: [PHP RFC: Make constructors and destructors return void](https://externals.io/rfc/make_ctor_ret_void)
- Discussion of this RFC: <https://news-web.php.net/php.internals/130808>
- Voting of this RFC: <https://news-web.php.net/php.internals/131272>

## Rejected Features

None.

## Changelog

- 2026-05-29: Include top 4000 composer packages analysis in RFC Impact section
- 2026-05-29: Mention that making `__construct` and `__destruct` a `Generator` will also be deprecated
- 2026-05-08: Initial version
