Req #75263 [Com]: function __construct(): void
Edit report at https://bugs.php.net/bug.php?id=75263&edit=1
ID: 75263
Comment by: spam2 at rhsoft dot net
Reported by: saymongcsw at gmail dot com
Summary: function __construct(): void
Status: Open
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:
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)
Previous Comments:
------------------------------------------------------------------------
[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
------------------------------------------------------------------------
[2017-09-26 20:38:36] saymongcsw at gmail dot com
Description:
------------
Can't declare VOID return type in constructor. (ex. https://3v4l.org/9slJl)
Test script:
---------------
<?php
class Say
{
public function __construct(): void
{
}
public function hello(): string
{
return 'Hello';
}
}
echo (new Say)->hello();
Expected result:
----------------
Hello
Actual result:
--------------
Fatal error: Constructor Say::__construct() cannot declare a return type in %s on line 3
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75263&edit=1
Thread (8 messages)