php5.3 几个新添功能

          php5.3也发布好久了,用到了几个函数,发到这里,一起学习下.
_callStatic() magic 方法

新增了魔术方法__callStatic,功能和__call类似,但是仅对static方法有效
class Foo
{
    public static function __callStatic( $name, $args )
    {
        echo "Called method $name statically";
    }
    public function __call( $name, $args )
    {
        echo "Called method $name";
    }
}
Foo::dog();       // outputs "Called method dog statically"
$foo = new Foo;
$foo->dog();      // outputs "Called method dog"
动态调用函数
class Dog
{
    public function bark()
    {
        echo "Woof!";
    }
}
$class = "Dog"
$action = "bark";
$x = new $class(); // instantiates the class "Dog"
$x->$action();     // outputs "Woof!"

Closures 功能 :
关于Closures,这是一个把函数定义成变量的玩意。
$string = "Hello World!";
$closure = function() use ($string) { echo $string; };
$closure(); //输出 Hello World!
$x = 1
$closure = function() use (&$x) { ++$x; }
echo $x . "\\n";
$closure();
echo $x . "\\n";
$closure();
echo $x . "\\n";
/*输出 :
1
2
3
*/

?:操作符

$a = true ?: false; // true
$a = false ?: true; // true
$a = "" ?: 1; // 1
$a = 0 ?: 2; // 2
$a = array() ?: array(1); // array(1);
$a = strlen("") ?: strlen("a"); //