View Single Post
  #10 (permalink)  
Old 04-21-2008, 06:32 AM
jegan jegan is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Posts: 161
jegan is on a distinguished road
Default Re: PHP Classes For Beginners

hi saravanan here i have writen a simple program to create objects

The Box object to calculate the area of box
PHP Code:
class Box
{
    var  
width;
    var 
height;

function  
setWidth(pmWidth)
{
     
$this->width    =    pmWidth;
}
function  
setHeight(pmHeight)
{
    
$this->height    =    pmHeight;
}
//This function now added to calculate the area of box object
function area()
{
    return 
$this->width*$this->height;
}


}

$object        =    new Box;    //The new key word used to create an object
$object->setWidth(100);
$object->setHeight(100);
print(
"Area of object box");
$object->area(); 
output

Area of object box :1000
__________________
Thanks & Regards,
Jegan CBK
"We will either find a way, or make one!”
Reply With Quote