【发布时间】:2011-11-27 23:04:51
【问题描述】:
我通常设置所有变量,即使它们可能不会返回任何内容。但现在我想知道:
如果我回显一个空变量会有什么危害?
例如。
<?php
$a = 'a';
$b = 'b';
if($a==$b)
{
$data = 'Yes they where the same';
};
echo $data;
?>
为什么我必须这样做?
<?php
$data = ''; // declare varibale
$a = 'a';
$b = 'b';
if($a==$b)
{
$data = 'Yes they where the same';
};
echo $data;
?>
感谢您的回答!
扩展问题:
什么是最佳实践:
$data = '';
或
$data;
或使用
if (isset($data)){
echo $data;
}
【问题讨论】:
-
变量...不变量
-
在启用错误/错误报告的情况下自行测试,
$a和$b的值不同。