PHP - Calling Methods from Class


To call an object's method, use the following format:


Here's a simple example that creates a class with a method, then creates an object from the class and calls the object's method:


        class MyClass {

          public function hello() {
            echo"Hello, World!";
          }//from  w ww.ja  v a  2  s. co  m

         $obj = new MyClass;
         $obj->hello();  // Displays"Hello, World!"


Related Topic