Home  >  Article  >  php教程  >  php5.3 注意事项说明

php5.3 注意事项说明

WBOY
WBOYOriginal
2016-06-13 11:43:56980browse

php5.3
新特性
1.支持命名空间(namespace)
5.3以前

复制代码 代码如下:


class Zend_Db_Table_Select {
//表示当前这个类文件位于Zend/Db/Table下
}


5.3

复制代码 代码如下:


namespace Zend/Db/Table
class Select {
}


2.支持延迟静态绑定
5.3以前(__CLASS__获得类名)self::who()

复制代码 代码如下:


class A {
    public static function who() {
        echo __CLASS__;
    }
    public static function test() {
        self::who();
    }
}
class B extends A {
    public static function who() {
         echo __CLASS__;
    }
}
B::test();
?>


输出A
5.3(__CLASS__获得类名)static::who();

复制代码 代码如下:


class A {
    public static function who() {
        echo __CLASS__;
    }
    public static function test() {
        static::who(); // 这里实现了延迟的静态绑定
    }
}
class B extends A {
    public static function who() {
         echo __CLASS__;
    }
}
B::test();
?>


输出B
 
3.支持goto语句
多数计算机程序设计语言中都支持无条件转向语句goto,当程序执行到goto语句时,即转向由goto语句中的标号指出的程序位置继续执行。
 
4.支持闭包

复制代码 代码如下:


$msg = "hello";
$callback  =  function() use($msg){
    print_r($msg);
}
$msg = "hello world!";
callback($callback);


输出
hello
hello world!

5.新增魔术方法__callStatic()
PHP中原本有一个魔术方法__call(),当代码调用对象的某个不存在的方法时该魔术方法会被自动调用。
新增的__callStatic()方法则只用于静态类方法。当尝试调用类中不存在的静态方法时,__callStatic()魔术方法将被自动调用。

6.新增一种常量定义方式(有时代码出错,如undefined HE,你要看看是否支持const)

复制代码 代码如下:


const CONSTANT = 'Hello World';


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn