Late Static Binding In Php Example

Late Static Binding In Php Example

Late Static binding feature was introduced in php 5.3.0. This is used to reference the called class in the context of static inheritance. This is used to solve the limitation of inheritance.

Example of Late Static Binding in PHP.


<?php
    class Country
    {
        public static function printName() 
        {
            return static::getName();
        }

        private static function getName() 
        {
            return 'USA';
        }
    }

    class India extends Country
    {
        public static function getName() 
        {
            return 'India';
        }
    }

    echo Country::printName(); 
	
	// output: USA
    echo India::printName(); 
	
	// output: India
?>



Advertisements

Add Comment

📖 Read More