I have a situation where I need to pass the name of the child class back to the parent class in order to take some action.
The way I have it set up at the moment is:
class SomeParentClass {
public function __construct($c = false){
...
}
}
class SomeChildClass extends SomeParentClass {
public function __construct(){
parent::__construct(__CLASS__){
...
}
}
}
This will pass the name of the child class back to the parent, but if the child class does not do this then the variable $c
will retain the bool value false
.
It works, it makes sense, but is this the cleanest way to do this? Is there a way to auto detect which child class has called parent::__construct()
without passing it as a variable?
Many thanks