PHP Specify the Return Type Hints for a Method

后端 未结 5 1132
庸人自扰
庸人自扰 2021-01-07 23:18

What is the correct syntax for me to specify the return type hints for a method?

For example, I have such a method:

private static function Construct         


        
5条回答
  •  我在风中等你
    2021-01-08 00:04

    For future reference, this is implemented for PHP 7, with the following syntax (quoted from source):

    function foo(): array {
        return [];
    }
    

    To answer your question now, as of PHP 7 (released around end of 2015) you will be able to do the following (as an example):

    The specification also allows for type hinting within and against interfaces; for those of us interested in adhering to SOLID principles.

    Source and more information: https://wiki.php.net/rfc/return_types

提交回复
热议问题