think about php late binding issues
Jul 06, 2016 pm 01:54 PM
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?
Reply content:
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

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
