Void as return type

后端 未结 5 837
忘了有多久
忘了有多久 2020-12-05 13:11

I was testing return types with PHP 7.

I\'ve created a simple script to test return types of PHP 7:



        
5条回答
  •  一整个雨季
    2020-12-05 13:29

    Edit:

    A new separate RFC for a void return type has been published, has passed the vote, and was implemented in PHP 7.1.
    There is now a void return type in PHP. :)

    Original Post:

    Taken from wiki.php.net:

    Future Work

    Ideas for future work which are out of the scope of this RFC include:

    • Allow functions to declare that they do not return anything at all (void in Java and C)

    So currently there is no way to declare that you don't return anything.
    I don't know what's best in your situation, but I'd probably just go with not declaring the return type for now.

    To answer your question whether there will be a void return type in PHP 7:
    There is no guarantee yet, but I think it is very likely that void or a synonym will be implemented in some way.

提交回复
热议问题