Home >Backend Development >PHP Tutorial >think about php late binding issues
Similar to the following code
<code>class father(){ public function __construct(){ echo "father"; } public static function instance($options = []) { if (is_null(self::$instance)) { self::$instance = new static($options); } return self::$instance; } } </code>
Then use the url or configuration to have a subclass to inherit father and call the instance() method to instantiate
How to determine which subclass is called statically?
Similar to the following code
<code>class father(){ public function __construct(){ echo "father"; } public static function instance($options = []) { if (is_null(self::$instance)) { self::$instance = new static($options); } return self::$instance; } } </code>
Then use the url or configuration to have a subclass to inherit father and call the instance() method to instantiate
How to determine which subclass is called statically?
In the method, you can use the get_called_class()
function to get the class name that calls this method, which is designed for late static binding.
namespace
Namespace