Req #79679 [Sus]: non-void return in __construct should generate at least warning
| From: | cmb@php.net | Date: | Sun, 07 Jun 2020 10:04:43 +0000 |
| Subject: | Req #79679 [Sus]: non-void return in __construct should generate at least warning | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-227346@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79679&edit=1
ID: 79679
Updated by: cmb@php.net
Reported by: michael dot vorisek at email dot cz
Summary: non-void return in __construct should generate at
least warning
Status: Suspended
Type: Feature/Change Request
Package: Scripting Engine problem
Operating System: any
PHP Version: 7.4.6
Block user comment: N
Private report: N
New Comment:
Just add a
void return type hint to __construct().
Previous Comments:
------------------------------------------------------------------------
[2020-06-06 19:35:08] requinix@php.net
While likely to be uncontroversial given the passing of the magic methods signature checks, this
sort of thing needs to be discussed on the internals list.
https://wiki.php.net/rfc/magic-methods-signature
https://www.php.net/mailing-lists.php
Note that __destruct is also affected, as well as possibly __clone, __set, __unserialize, __unset,
and __wakeup.
------------------------------------------------------------------------
[2020-06-06 14:38:02] michael dot vorisek at email dot cz
Description:
------------
__construct is special methods and it should be not allowed to return any value
Test script:
---------------
class A {
public function __construct() {
return 5;
}
}
class B extends A {
public function __construct() {
var_dump(parent::__construct());
}
}
$b = new B();
Expected result:
----------------
PHP warning
Actual result:
--------------
int(5)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79679&edit=1