|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-09-26 20:38 UTC] 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 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 16:00:01 2025 UTC |
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?