CallStatic Method

 <?php

//When we try to call any private static method from outside the class at that time __callStatic()
//method will automatically call.

class Student
{
    private static function hello($name)
    {
        echo "This is static hello function"."<br>";
        echo "Good Morning : $name";
    }
    public static function __callStatic($method, $args)
    {
        echo "This is Private Method : $method" . "<br>";

        if(method_exists(__class__, $method))
        {
            call_user_func_array([__class__,$method], $args);
        }
        else
        {
            echo "Method does not exist : $method";
        }
    }
}
Student::hello("Hello World");

//  OUTPUT:
//This is Private Method : hello
// This is static hello function
// Good Morning : Hello World

?>

Comments

Popular posts from this blog

Logical_Operators

SubQuery with EXISTS and NOT EXISTS in PHP

Get Functions