Home > Backend Development > PHP Tutorial > PHP Static delayed static binding usage analysis, static_PHP tutorial

PHP Static delayed static binding usage analysis, static_PHP tutorial

WBOY
Release: 2016-07-12 08:56:51
Original
1061 people have browsed it

PHP Static delayed static binding usage analysis, static static

The example in this article describes the usage of PHP Static delayed static binding. Share it with everyone for your reference, the details are as follows:

After PHP5.3, delayed static binding static was introduced. What problem is it intended to solve? A long-standing problem with PHP's inheritance model is that it is difficult to reference the final state of an extended class in the parent class. Let’s look at an example.

class A 
{ 
  public static function echoClass(){ 
    echo __CLASS__; 
  }
  public static function test(){ 
    self::echoClass();    
  }
}
class B extends A 
{    
  public static function echoClass() 
  { 
     echo __CLASS__; 
  } 
} 
B::test(); //输出A

Copy after login

A new feature has been added to PHP5.3: delayed static binding, which means that expressions or variables that were originally fixed in the definition phase are changed to be determined in the execution phase. For example, when a subclass inherits a parent class When it is a static expression, its value cannot be changed. Sometimes you don't want to see this situation.

The following example solves the problem raised above:

class A 
{ 
  public static function echoClass(){ 
    echo __CLASS__; 
  } 
  public static function test() 
  { 
    static::echoClass();    
  } 
} 
class B extends A 
{    
  public static function echoClass(){ 
     echo __CLASS__; 
  } 
} 
B::test(); //输出B

Copy after login

static::echoClass(); on line 8 defines a static delayed binding method. The method that was originally defined will not be executed until B calls test.

Readers who are interested in more PHP-related content can check out the special topics of this site: "Summary of PHP office document operation skills (including word, excel, access, ppt)", "Summary of PHP date and time usage", "php-oriented "Introduction Tutorial on Object Programming", "Summary of PHP String Usage", "Introduction Tutorial on PHP MySQL Database Operation" and "Summary of Common PHP Database Operation Skills"

I hope this article will be helpful to everyone in PHP programming.

Articles you may be interested in:

  • A brief talk about PHP delayed static binding
  • Analysis of PHP delayed static binding examples
  • PHP delayed static binding Sharing of custom examples
  • Start the PHP Static keyword tour mode
  • Analysis of static static properties and static methods in PHP
  • The static keyword in PHP and the relationship with the self keyword Difference
  • PHP object-oriented journey: in-depth understanding of static variables and methods
  • A brief analysis of the use of PHP variable modifier static
  • Analysis of the use of static, const and define in PHP Difference
  • Introduction to the use of static methods and static variables in PHP classes

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1111342.htmlTechArticlePHP Static delayed static binding usage analysis, static static This article describes the usage of PHP Static delayed static binding. Share it with everyone for your reference, the details are as follows: PHP5.3 has introduced...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template