Doc #76311 [Ver]: __construct/destruct/clone do not have return types
| From: | requinix@php.net | Date: | Tue, 08 May 2018 16:47:17 +0000 |
| Subject: | Doc #76311 [Ver]: __construct/destruct/clone do not have return types | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-15661@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76311&edit=1
ID: 76311
Updated by: requinix@php.net
Reported by: Andy_Schmidt at HM-Software dot com
-Summary: __construct/destruct do not have return types
+Summary: __construct/destruct/clone do not have return types
Status: Verified
Type: Documentation Problem
Package: Class/Object related
PHP Version: 7.2.5
Block user comment: N
Private report: N
New Comment:
True, but __wakeup allows for a void return type. Which I don't mind because its counterpart
__sleep does have a return type.
To me it's more the fact that __construct/destruct are particularly special methods and
explicitly disallow return types. __clone too, now that I look at the list.
Previous Comments:
------------------------------------------------------------------------
[2018-05-08 16:39:53] cmb@php.net
> Constructors and destructors do not have the concept of a return
> type.
The same is true for some of the other magic methods (e.g.
__wakeup()).
------------------------------------------------------------------------
[2018-05-08 15:50:26] requinix@php.net
Constructors and destructors do not have the concept of a return type. The docs showing anything at
all, even void, is incorrect.
------------------------------------------------------------------------
[2018-05-08 15:37:05] Andy_Schmidt at HM-Software dot com
Description:
------------
According to PHP's manual:
http://php.net/manual/en/language.oop5.decon.php
the signature of the __destruct method is:
void __destruct ( void )
Consequently, the following syntax would be correct for 7.2, now that a "void" type hint
is available:
function __destruct(): void {}
Actual result:
--------------
PHP Fatal error: Destructor __destruct() cannot declare a return type
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76311&edit=1