How to create a public static method in PHP?

Member

by melvina , in category: Technology , 3 years ago

How to create a public static method in PHP?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by braeden , 3 years ago

Static method is a member of class that is called directly by class name without creating an instance.In PHP uou can create a static method by using static keyword.

Example:

1
2
3
4
5
6
7
class A {
    public static function sayHello() {
        echo 'hello Static';
    }
}

A::sayHello();