douxiandiyo58855 2016-11-14 00:57
浏览 153
已采纳

PHP 7.1中的隐式void返回?

I found in here the new spec: https://wiki.php.net/rfc/void_return_type

function lacks_return(): void {
    // valid
}
function returns_nothing(): void {
    return; // valid
}
function returns_void(): void {
    return void; // valid
}

Ask: Do you know what happens behind the scene. Will the lacks_return function return actually void?

  • 写回答

2条回答 默认 最新

  • dsaxw4201 2016-11-14 01:05
    关注

    You could have tested this yourself pretty easily:

    function lacks_return(): void {
    }
    
    function returns_nothing(): void {
        return;
    }
    
    echo gettype(lacks_return()); // NULL
    echo gettype(returns_nothing()); // NULL
    

    So the answer is yes - there is an implicit empty (null) return so you could either use an empty return or skip it completely. Which kind of makes sense - returning nothing is the same as not returning anything?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置