关于PHP中变量的判定

由于PHP解释性语言,所以一个变量即使没有定义也可以被使用而不会引起error。请看下面这个例子:

 

输出的结果是:

empty

no set

 

Notice: Undefined variable: test in C:/AppServ/www/test2.php on line 11

null

 

Notice: Undefined variable: test in C:/AppServ/www/test2.php on line 14

no defined

 

Notice: Undefined variable: test in C:/AppServ/www/test2.php on line 18

case 0

有其实最后一个switch判断,这是一个比较隐晦的错误,所以在使用前进行一次判断还是有意义的。同时我们可以看到有些的判断方式会引起Notice而有些不会。至于判断的解读,请参考另一篇文章:http://blog.csdn.net/autofei/archive/2010/05/24/5619004.aspx

posted on 2010-06-17 11:28  爱你一万年123  阅读(180)  评论(0编辑  收藏  举报

导航