Home > Backend Development > PHP Tutorial > Simple example of static postponed binding in PHP_PHP tutorial

Simple example of static postponed binding in PHP_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:27:12
Original
763 people have browsed it

Simple example of static late binding in PHP

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

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 '

 ;

echo C::test();

echo '

 ;

echo B::test2();

echo '

 ;

echo C::test2();

echo '

 ;

echo A::test();

echo '

 ;

echo A::test2();

echo '

 ;

// Output results

 B

C

 456789

abcdef

 A

 123456

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/820417.htmlTechArticlePHP static delayed binding simple example I haven’t used this new feature much, but it’s not actually new. Try it. Well, inheritance of static classes is very convenient now class A { protected static $def = '12345...
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