How to I get the object $this
of that class where the current function was called from?
class a extends zebra {
function xyz() {
...
b::somestaticmethod();
}
}
class b {
public static function somestaticmethod() {
$callerObj = get_called_class();
}
}
The function get_called_class()
fetches the name of the calling class in string format. What I am looking for is that, is there a way to get the object ($this
) from the context of the calling class, just like what would have happened if $this
was passed as an argument as below.
b::somestaticmethod($this);
Why?
I am planning to implement a polymorphic behavior on the somestaticmethod()
method, which will check the calling class and based on the ancestor
of that class guide the logic further.