我继承了一些代码,以前的编码员在其中写了这个:
if (!not_null($page)) {
die('<b>Error!</b><br><b>Unable to determine the page link!<br><br>');
}
这有什么好处,而不是仅仅说: if (is_null($page))
这对我来说似乎是不必要的混乱。
我继承了一些代码,以前的编码员在其中写了这个:
if (!not_null($page)) {
die('<b>Error!</b><br><b>Unable to determine the page link!<br><br>');
}
这有什么好处,而不是仅仅说: if (is_null($page))
这对我来说似乎是不必要的混乱。
not_null必须是本地函数。
它不是标准的 PHP 函数。
不知道做什么not_null,是不可能说的。由于not_null是用户定义的函数,它可以做任何事情
如果,在检查之后,你发现这not_null是在做一个简单的比较,你可以以可读性的名义重构代码:
if (is_null($page))
die('<p><strong>Error!</strong><br>Unable to determine the page link!</p>')
或者
if ($page === null)
die('<p><strong>Error!</strong>Unable to determine the page link!</p>')
PS - 不要使用<b>-<strong>改为使用。此外,当您需要多个换行符时,请使用 a<p>而不是 multiple <br>。您的示例代码<b>在错误消息上有一个未关闭的标签。
文档
我相信 PHP中没有not_null函数。
你应该用什么?
使用=== nullor!== null代替显式调用函数。
这样做实际上看起来更糟,因为可以简单地写在 if 语句中:
if($page==null)它的计算速度比使用这个函数快。您也可以尝试if(!$page)快速评估。