I’m having troubles finding a class name after extending other classes. Here are the relevant classes:
class Home extends Controller {
public function test() {
Example::all();
}
}
Class Example extends Active {
//Variables
}
Class Active extends Database {
public function all() {
//This is where I need to store a variable containing the class name Example.
}
}
I’m trying to retrieve the name of the Class Example in Class Active from when it is called from class Home, however I’ve found it impossible to do this so far without adding an extra argument (which I don’t want to do).
You are looking for
get_called_class— the “Late Static Binding” class nameExample (demo)
Note that I have changed the signature of
Active::alltostaticbecause calling non-static methods statically will raiseE_STRICTwarnings. In general, you want to avoid static methods and Late Static Binding.