They do have different outcomes in the case where you are having a class that inherits from this class; same as if you replace new self() with new static()
Nov 19, 2020
3
Level 75
PHP general question
At times in a helper class I have something like:
protected static $instance;
if (!isset(self::$instance)) {
self::$instance = new self();
}
It's always worked. But recently I ran across this:
protected static $instance;
$myClass = get_called_class();
self::$instance = new $myClass;
I have never used get_called_class(), both work. Is one better than the other.
Level 104
Please or to participate in this conversation.