在OOP中,构造函数和析构函数是很重要的,在PHP4中,可以用和类名相同的方法名称来声明构造函数,比如 

class a{

function a()

{


}

}


在PHP5中,是用新的关键字_construct来实现了,而析构函数则用__destruct()

比如一个例子:

class Person {

function __construct($name)

{

$this->name = $name;

}


function getName()

{

return $this->name;

}


private $name;

};


$judy = new Person("Judy") . "\n";

$joe = new Person("Joe") . "\n";


print $judy->getName();

print $joe->getName();