Re: [RFC] Deprecate returning values from __construct() and __destruct()
| From: | Mirco Babin | Date: | Thu, 21 May 2026 08:01:37 +0000 |
| Subject: | Re: [RFC] Deprecate returning values from __construct() and __destruct() | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-130980@lists.php.net to get a copy of this message | ||
Hello Tim Düsterhus,
> following Rowan’s request from the earlier “let the "new" operator fail
> when the __construct( ) function returns a value” discussion [1], I have
> now created a dedicated RFC to deprecate returning values from
> __construct() and __destruct().
>
> Please find the RFC text at:
> https://wiki.php.net/rfc/deprecate-return-value-from-construct
The RFC should also include "yield". Because "yield" also returns a value.
For example:
https://3v4l.org/Z4dMTF#v8.5.3
```php
class SomeTheoreticalYieldExample
{
public $value;
public function __construct()
{
$this->value = 'Some value';
yield 1; // Deprecated: yielding from a constructor is deprecated
}
}
$it = new SomeTheoreticalYieldExample();
var_dump($it->value); // PHP 8.5 surprise/bug, it is NULL
```
Kind Regards,
Mirco Babin