PHP - Calling Methods from Class

Introduction

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

$object->method();

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:

Demo

<?php
        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!"
?>

Result

Related Topic