<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>构造方法</title>
</head>

<body>
<?php
class MyObject{
	public $object_name;								//图书名称
	public $object_price;									//图书价格
	public $object_num;									//图书数量
	public $object_agio;									//图书折扣
/*  构造方法  */
function __construct($name,$price,$num,$agio){			//通过参数给成员变量赋值
		$this -> object_name = $name;
		$this -> object_price = $price;
		$this -> object_num = $num;
		$this -> object_agio = $agio;
	}
/*  *********  */
	function setObjectName($name){						//声明方法setObjectName()
		$this -> object_name = $name;						//设置成员变量值
	}
	function getObjectName(){							//声明方法getObjectName()
		return $this -> object_name;
	}
}
$c_book = new MyObject('Western-style clothes',1500,5,8);		//实例化对象
echo $c_book -> getObjectName();							//调用方法getObjectName
?>

</body>
</html>
