Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Static Method in PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 116
    Comment on it

    When you declare class method as static then these method can be called without instantiating of the class .

    When you declare a method or a variable static then we must use static keyword before declare this and when accessing these method or properties outside the class then we have to use class name followed by :: then followed by property name.


    Example of static method :-

    class MyClass {
        public static function myStaticMethod() {
            echo "this is my static method";
        }
    }
    
    MyClass::myStaticMethod();
    

    So in this example we have declared our method static and when we want to access this outside the class we have used our class followed by :: and then method .

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: