How to create a public static method in PHP?

Member

melvina

by melvina , in category: Technology , a month ago

How to create a public static method in PHP?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by braeden , a month 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();