Call class methods directly : Class Method « Class « PHP






Call class methods directly


<?php
   class Visitors
   {
      public function greetVisitor()
      {
         echo "Hello<br />";
      }

      function sayGoodbye()
      {
         echo "Goodbye<br />";
      }
   }

   Visitors::greetVisitor();
   $visitor = new Visitors();
   $visitor->sayGoodbye();
?>

           
       








Related examples in the same category

1.Pass class instance as parameter
2.Accessing the Attributes of a Class by Using Functions
3.A Class with a Method
4.Accessing a Property from Within a Method
5.A Class with a Method
6.Access properties
7.Calling an Overridden Method (PHP 5 Syntax)
8.Class Member Overloading
9.Class Member and Method Definitions
10.Defining three member functions for Cat
11.Overriding Methods
12.The Method of a Child Class Overriding That of Its Parent (PHP 4 Syntax)