Share on Google+Share on Google+

PHP Late Static Binding

Advertisement
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() {

static::classIdentifier();

}

}

class Two extends One {

public static function classIdentifier() {

echo __CLASS__;

}

}

Two::classtest();

?>

 

Output:

Two

Advertisements

Posted on: March 2, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.