What's the proper way to get new self()
to use the current instance's constructor? In other words, when I do:
class Foo{
function create(){
return new self();
}
}
Class Bar extends Foo{
}
$b = new Bar();
echo get_class($b->create());
I want to see: Bar
instead of: Foo
This should work.
Shows:
UPD:
If you want non-statics, then:
Shows:
Store the class type in a temp variable and then return a new instance of it.
If you call a function from a child class then it if it will search the nearest parent to call it. This is inheritance.
The idea is to use polymorphism in this situation. Redeclaring a function from child override it's parent's activity. If you want to run it's parent function too then you have to call it like
parent::callee();