Example of PHP delayed static binding

Source: Internet
Author: User
Tags echo b
In PHP5.3, the keyword static is added to the class to implement latestaticbinding. let's take a look at an example to learn how to use this new feature, actually, it's not new. try it. it's very convenient to inherit static classes now.

<? Phpclass A {protected static $ def = '000000'; public static function test () {echo get_class (new static);} public static function test2 () {echo static :: $ def ;}} class B extends A {protected static $ def = '000000';} 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 result BC456789abcdefA123456

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.