现在的位置: 首页 > 综合 > 正文

关于PHP中变量的判定

2013年08月15日 ⁄ 综合 ⁄ 共 778字 ⁄ 字号 评论关闭

由于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

抱歉!评论已关闭.