PHP Late Static Binding


 

PHP Late Static Binding

In this current PHP tutorial Section, we will study about late static binding in PHP, what is late static binding, how to use late static binding among classes, what are the uses of it in PHP etc.

In this current PHP tutorial Section, we will study about late static binding in PHP, what is late static binding, how to use late static binding among classes, what are the uses of it in PHP etc.

PHP Late Static Binding:

A new feature called late static binding is introduced in PHP 5.3.0 which can be used to refer the called class.

The name late static binding is coined because of the static:: will no longer be resolved using the class where the method is defined.

Example:

<?php

class One {

public static function classIdentifier() {

echo __CLASS__;

}

public static function classtest() {

self::classIdentifier();

}

}

class Two extends One {

public static function classIdentifier() {

echo __CLASS__;

}

}

Two::classtest();

?>

 

Output:

One

Example:

<?php

class One {

public static function classIdentifier() {

echo __CLASS__;

}

public static function classtest() {

0

static::classIdentifier();

}

}

1

class Two extends One {

public static function classIdentifier() {

2

echo __CLASS__;

}

}

3

Two::classtest();

?>

4

 

Output:

Two

5

Ads