Friday, 9 April 2010

How to Declare a Class and Initializing a Class Object ?

Declaring Class in PHP5:
In PHP5 you create a new class using "class" keyword.
The basic declaration of a class:


class myClass
{
   public function getAge()
   {
      echo "Inside Method";
   }
}
 
Initializing an Class Object in PHP5

To access the class from the outside world i.e. outside the scope of
class; you will need to create an object instance of the class. This
can be achieved using "new" operator.

Initializing Class 

class myClass
{
   public function myAge()
   {
      echo "Inside Method";
   }
}     
$myClassObj = new myClass();
 
//Calling class method... 
$myClassObj->myAge(); 

1 comment:


  1. Good day. I was impressed with your article. Keep it up . You can also visit my site if you have time. Thank you and Bless you always.
    Hire Yii Framework Team in India

    ReplyDelete