Home > Backend Development > PHP Tutorial > think about php late binding issues

think about php late binding issues

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-06 13:54:07
Original
1605 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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.

namespaceNamespace

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template