关闭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);
}