oop - PHP: get_called_class() vs get_class($this) -
in php difference between get_called_class() , get_class($this) when used inside instance?
example:
class { function dump() { echo get_called_class(); echo get_class($this); } } class b extends {} $a = new a(); $b = new b(); $a->dump(); // output 'aa' $b->dump(); // output 'bb' is there difference in case?
when should using 1 or other get_called_class() or get_class($this)?
in case there's no difference, because $this points correct instance class name resolved using get_class().
the function get_called_class() intended static methods. when static methods overridden, function return class name provides context current method that's being called.
Comments
Post a Comment