Req #75263 [Com]: function __construct(): void
Edit report at https://bugs.php.net/bug.php?id=75263&edit=1
ID: 75263
Comment by: elliseprod at gmail dot com
Reported by: saymongcsw at gmail dot com
Summary: function __construct(): void
Status: Not a bug
Type: Feature/Change Request
Package: Class/Object related
Operating System: any
PHP Version: 7.1.10RC1
Block user comment: N
Private report: N
New Comment:
Actually, watch the PHP doc : https://www.php.net/manual/en/language.oop5.decon.php
__construct ([ mixed $args = "" [, $... ]] ) : void
So, I agree with having the opportunity to declare VOID return type in constructor
Previous Comments:
------------------------------------------------------------------------
[2018-01-03 16:45:23] Andy_Schmidt at HM-Software dot com
Since the constructor must use
return 'somevalue';
to return a value, I consequently do believe that declaring:
function __construct(): void { ... }
would actually be the proper way to document that restriction - now that "void" is a valid
function return type?
------------------------------------------------------------------------
[2017-09-27 05:22:41] requinix@php.net
Constructors in object-oriented languages do not have return types.
------------------------------------------------------------------------
[2017-09-26 22:54:51] spam2 at rhsoft dot net
but to gain what?
it's a magic function with special behavior anyways (see new my_class(1, 2) which calls
__constrcut without naming it)
------------------------------------------------------------------------
[2017-09-26 21:48:50] saymongcsw at gmail dot com
I mean add possibility for :void in constructor without behavior change.
Constructor would be good for configure object but without constructors in PHP works too...
(https://3v4l.org/QnvEi)
also see link in comment above that show in hhvm-3.21.0 works as expected.
------------------------------------------------------------------------
[2017-09-26 21:29:34] spam2 at rhsoft dot net
why do you think a void retunr-type would be correct for __construct()
$x = new my_class(1, 2)
call __construct(1, 2) of my_class and returns a object instance
------------------------------------------------------------------------
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=75263
--
Edit this bug report at https://bugs.php.net/bug.php?id=75263&edit=1
Thread (8 messages)