dsc7188 2016-10-18 12:00
浏览 16
已采纳

在PHP中返回布尔值时的最佳实践

I noticed lately that eclipse is suggesting me the use of constants TRUE and FALSE from core.php when returning true or false from a function.

In other words should I use

function misc () 
{
    ...

    return true;
}

or

function misc () 
{
    ...

    return TRUE;
}

I know they are the same thing because of the way these constants are defined in core.php

define ('TRUE', true);
define ('FALSE', false);

So if anyone could explain what's best practice I would really appreciate.

  • 写回答

1条回答 默认 最新

  • douxiajiao8445 2016-10-18 18:06
    关注

    Best practice is, if you do not have your own coding standard, to follow the FIG coding standards.

    According to FIG PSR-2, there is no ambiguity what so ever about this particular issue:

    The PHP constants true, false, and null MUST be in lower case.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题