I am using the NetBeans editor. In the following code, there is no error, but I am confused about something: why do we return new static
?
class test {
static public function getnew(){
return new static;
}
}
class child extends test {}
$obj1 = new test ();
$obj2 = new $obj1;
var_dump($obj1!==$obj2);
$obj3 = test::getnew();
var_dump($obj3 instanceof test);
$obj4 = child::getnew();
var_dump($obj4 instanceof child );
The resulting output:
boolean true
boolean true
boolean true
So what is the return new static
doing here?