Skip to content
PHP News
Search
Implemented PHP 8.6

Deprecate returning values from __construct() and __destruct()

Deprecates returning a value, or using yield, in __construct() and __destruct(), while a bare return; stays legal.

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

Primary vote · 2/3 majority

39 Yes 0 No 100% approval

This poll has closed.

It passed 39 to 0, with no abstentions, clearing the two-thirds majority it needed. Voting closed on June 29, 2026. The RFC targets PHP 8.6, and the page marks it as implemented.

Summary

You can't give __construct() or __destruct() a return type, not even void, but PHP still lets you write return 123; inside them. The value just goes nowhere, which can confuse people. This RFC from Tim Düsterhus deprecates returning a value from either method.

Show me

Here is a trimmed version of the RFC's example:

class Foo
{
    public function __construct()
    {
        return 123; // Deprecated: Returning a value from a constructor is deprecated
    }
}

class Bar
{
    public function __construct()
    {
        if (random_int(0, 1)) {
            return; // Skipping the rest of the logic remains legal.
        }

        echo "Constructing", PHP_EOL;
    }
}

A bare return; with no value still works, so you can keep using it to skip the rest of the method.

Using yield inside a constructor or destructor is deprecated too, since it turns the method into a generator that returns a Generator object.

The deprecation is raised at compile time, not when the code runs. In the next major version it becomes an error, matching how a void function already fails if it returns a value.

You can still call __construct() and __destruct() directly. For example, parent::__construct() works the same as before.

What it means for existing code

The deprecation alone doesn't break anything. Your code still runs, but you'll see a deprecation notice. Once it becomes an error in a later major version, code that returns a value will stop working.

This pattern is rare. Juliette Reinders Folmer checked the top 4,000 Composer packages and found 77 return statements with a value, across 59 files in 36 packages, and 21 of them were return $this;. To fix yours, drop the value from the return.