Why is new static in closure (in the method of the static class) equal to new self in PHP5.5, and is it correctly connected in PHP5.6?
Given:
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 { }
then
Child::make($someArray); // PHP5.5 FatalError: cannot instantiate abstract class Parent // PHP5.6 works fine, as expected
In 5.5, this will work as expected:
public static function make($array) { $child = get_called_class(); return array_map(function ($el) use ($chlid) { return new $child($el); }, $array); }
but why is this happening? I did not find any mention of php.net regarding static binding changes in 5.6.
source share