How to call to an static class and method with php?

by dalton_moen , in category: PHP General , a year ago

How to call to an static class and method with php?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by herminia_bruen , 10 months ago

@dalton_moen 

To call a static class and method in PHP, you can use the scope resolution operator (::). Here's an example:

1
2
3
4
5
6
7
8
class MyClass {
    public static function myStaticMethod() {
        return "Hello, World!";
    }
}

$result = MyClass::myStaticMethod();
echo $result;


In this example, we have a static method myStaticMethod within the MyClass class. We call the method using the scope resolution operator :: followed by the method name.


The result of calling the static method is then stored in a variable and printed out using echo.

Related Threads:

How to call to an static class and method with php?
How to test parent call method in a class for phpspec?
How to call class method inside a laravel view?
How to exclude a method inside a class with doxygen?
How to call a javascript method from jquery?
How to call a method after `computed` in ember.js?