How to create a public static method in PHP?

Member

by melvina , in category: Technology , 4 years ago

How to create a public static method in PHP?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

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


Related Threads:

What is difference between Method overriding and overloading in PHP?
How to access a Static Member of a Class in PHP?
How to Create a Composer Package in 2025?
What Are the Best Practices for Optimizing Performance in Vue.js Applications?
What Is Php Error Handling in 2025?
How to Disable Browser Caching for My Website in 2025?