Home > Backend Development > PHP Tutorial > PHP delayed static binding example sharing_PHP tutorial

PHP delayed static binding example sharing_PHP tutorial

WBOY
Release: 2016-07-13 10:24:07
Original
803 people have browsed it

I haven’t used this new feature much, and it’s not really new at all. Give it a try. Inheriting static classes is very convenient now

<&#63;php
class A {
 protected static $def = '123456';

 public static function test() {
  echo get_class(new static);
 }

 public static function test2() {
  echo static::$def;
 }
}

class B extends A {
 protected static $def = '456789';
}

class C extends A {
 protected static $def = 'abcdef';
}

echo B::test();
echo '<br>';
echo C::test();
echo '<br>';
echo B::test2();
echo '<br>';
echo C::test2();
echo '<br>';
echo A::test();
echo '<br>';
echo A::test2();
echo '<br>';
Copy after login

// 输出结果
B
C
456789
abcdef
A
123456

Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825540.htmlTechArticleI haven’t used this new feature much, but it’s not actually new. Give it a try, now the inheritance of static classes Very convenient phpclass A { protected static $def = '123456'; public static function test...
Related labels:
php
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