PHP Static Delay Binding

Source: Internet
Author: User

PHP 5.3.0 adds a static keyword to refer to the current class, that is, to implement a lazy static binding, while PHP 5.3.0 also implements the Get_called_class () function to find the currently called class, and allows the use of variables as class names to invoke static properties or methods

(PHP 5 >= 5.3.0, PHP 7)

get_called_class-Late static binding ("late static binding") class name

Description

String Get_called_class (void)

Gets the class name of the static method call.

return value

Returns the name of the class, or FALSE if not called in the class.

Example

Use of Example #1 Get_called_class ()

<?php

class Foo {static public function test () {Var_dump (Get_called_class ()); } }

Class Bar extends Foo {}

Foo::test (); Bar::test ();

?>

The above routines will output:

String (3) "foo" string (3) "Bar"

PHP Static Delay Binding

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.