__construct function example

/*A construct function used to set up default values for objects. We know that when an object is made a construct function automatically called for that object.

A construct function accept parameters to set default values for specifice object…

class people
public $age;
public $name;
function __construct($a,$n)
$this->age = $a;
$this->name = $n;

$tanvir = new people(22,’tanvir’);

echo $tanvir->name.’   ‘.$tanvir->age;


/*Please note that i placed public keyword before function, actually its not mandatory you can ignore it, cause the default keyword is a public keyword …

One more thing is that when we are using php version 4.0 that not support __construct() function
syntax for php 4.0 is : function class_name(){}


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s