Doc #76311 [->Ver]: __construct/destruct/clone do not have return types
| From: | requinix@php.net | Date: | Tue, 08 May 2018 17:08:09 +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-15663@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/clone do not have return types
-Status: Verifiedo
+Status: Verified
Type: Documentation Problem
Package: Class/Object related
PHP Version: 7.2.5
Block user comment: N
Private report: N
New Comment:
https://www.google.com/search?q=why+dont+constructors+have+return+types
This isn't about method signatures. This is about what constructors, destructors, and cloning
represent. The fact that PHP allows you to specify their behavior using a syntax that resembles that
of normal methods is besides the point.
Previous Comments:
------------------------------------------------------------------------
[2018-05-08 17:05:14] Andy_Schmidt at HM-Software dot com
I understand that some methods had always implicitly disallowed return values before there had been
a syntax to do so explicitly. The hard syntax error certainly was proper before 7.1.
However, this is 2018. Why would we still force occasional PHP users from having to memorize the
signature for each and every magic method?
Now that "void" is a type hint, it seems that an author writing self-documenting code (for
the benefit of less-versed coworkers) should not be penalized with run-time errors for explicitly
defining VOID?
I respectfully suggest that with 7.1 and higher, the message category
"... cannot declare a return type"
should simply recognize the now-available type "void" as being a perfectly expression of
the implicit rule!
------------------------------------------------------------------------
[2018-05-08 16:49:06] requinix@php.net
Related To: Bug #76312
------------------------------------------------------------------------
[2018-05-08 16:47:16] requinix@php.net
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.
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=76311
--
Edit this bug report at https://bugs.php.net/bug.php?id=76311&edit=1