View Single Post
  #21 (permalink)  
Old 04-23-2008, 07:25 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

eacy to use constructors in php class. when we creating a objects from using the new keyword the constructor function automatically executes
PHP Code:
class Box
{
    var  
width;
    var 
height;

        function 
box($pmWidth,$pmHeight)
{
    
$this->width    =$pmWidth;
   
$this->height=,$pmHeight;
}
function 
area()
{
    return 
$this->width*$this->height;
}
}

//This is syntax for Calling of constructor function 
$object        =    new Box(100,100);    //The new key word used to create an object
echo “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
Sponsored Links