php 中的陷阱

来源:互联网 发布:有赞 源码 编辑:程序博客网 时间:2024/06/06 12:42
count(false)  > 0 // truecount(0) > 0 // true"随便一个字符串" == 0 // true"不是0的一个字符串" == true // true$a = "2级";$b = "14级";$b > $a // false 不要做这样的比较isset("") === true // 0 === false // false iconv("UTF-8", "GB2312", $text)  // 容易遇到特殊的字符,会截断// 建议使用iconv("UTF-8", "GB2312//TRANSLIT", $text)exec($a, $b);  // $b 是负责记录输出,会不断累加strlen("宝宝树") == 9mb_strlen("宝宝树") == 3 //强烈建议使用 mb_strimwidth("宝宝树babytree", 0, 7, "", "UTF-8") == "宝宝树b"  // 推荐在web端截字function abcTest () {}function abctest () {} //上面两个函数是一个,php会忽略大小写//静态变量的问题class A {    static $x = 1;    public static function fun() {        echo self::$x;    }}class B extends A {    static $x = 2;}B::fun();   //输出是1,而不是2// 判断是否是数字,用is_numeric,不要用is_int,因为在浏览器传过来的,是一个字符串,不是整型is_numeric("1234")  // trueis_int("1234")   // false$a = $a . $b; //不建议使用,效率低,和下面的效率相比,是一个数量级的差别$a .= $b;// memcache,tt的key不能有中文,空格 允许的字符集有 "a-Z", "0-9", "_", "-"//feof死循环// if file can not be read or doesn't exist fopen function returns FALSE$file = @fopen("no_such_file", "r");// FALSE from fopen will issue warning and result in infinite loop herewhile (!feof($file)) {}

转:http://www.kubiji.cn/topic-id2435.html

原创粉丝点击