Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关闭PHP5.5与5.6中的后期静态绑定_Php_Php 5.5_Php 5.6 - Fatal编程技术网

关闭PHP5.5与5.6中的后期静态绑定

关闭PHP5.5与5.6中的后期静态绑定,php,php-5.5,php-5.6,Php,Php 5.5,Php 5.6,为什么闭包中的new static(在类static方法中)等于PHP5.5中的new self,而它在PHP5.6中被正确绑定 鉴于: abstract class Parent { public function __construct($something) { $this->something = $something; } public static function make($array) { retu

为什么闭包中的
new static
(在类
static
方法中)等于PHP5.5中的
new self
,而它在PHP5.6中被正确绑定

鉴于:

abstract class Parent {
    public function __construct($something)
    {
        $this->something = $something;
    }

    public static function make($array)
    {
        return array_map(function ($el) {
            return new static($el);
        }, $array);
    }
}

class Child extends Parent {

}
然后

在5.5中,这将按预期工作:

public static function make($array)
{
    $child = get_called_class();

    return array_map(function ($el) use ($chlid) {
        return new $child($el);
    }, $array);
}

但为什么会这样?我在php.net上没有发现任何关于5.6中静态绑定更改的内容。

看起来像是固定的。

是的。更有趣的是,它已经在5.4.38中修复,但显然没有包含在5.5.0中。Thanks@JarekTkaczyk:php一次支持多个分支,因此任何5.4.*都不一定在5.5.*之前。在本例中,5.4.30和5.5.14在上发布。当然。我不知道发布日期:)
public static function make($array)
{
    $child = get_called_class();

    return array_map(function ($el) use ($chlid) {
        return new $child($el);
    }, $array);
}