【发布时间】:2012-12-16 09:32:17
【问题描述】:
我有以下代码片段:
$active_from = '31-12-2009';
if(list($day, $month, $year) = explode('-', $active_from)
&& !checkdate($month, $day, $year)) {
echo 'test';
}
为什么会出现未定义变量错误?
list($day, $month, $year) = explode('-', $active_from) 返回true,所以list() 被评估,不是吗?我想,应该定义变量吗?我要监督什么?
这在我看来是一样的并且不会引发错误:
$active_from = '31-12-2009';
list($day, $month, $year) = explode('-', $active_from);
if(checkdate($month, $day, $year)) {
echo 'test';
}
这不会引发错误:
if((list($day, $month, $year) = explode('-', $active_from)) && checkdate($month, $day, $year)) {
但我真的不明白为什么:-)
感谢解释
【问题讨论】:
-
这里没有错误codepad.org/33BV3EsO
标签: php if-statement short-circuiting