[php]代码库
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>类常量</title>
</head>
<body>
<?php
class MyObject{
const BOOK_TYPE = 'PHP函数参考大全'; //声明常量BOOK_TYPE
public $object_name; //声明变量,用来存放图书名称
function setObjectName($name){ //声明方法setObjectName()
$this -> object_name = $name; //设置成员变量值
}
function getObjectName(){ //声明方法getObjectName()
return $this -> object_name;
}
}
$c_book = new MyObject(); //实例化对象
$c_book -> setObjectName("PHP类"); //调用方法setObjectName
echo MyObject::BOOK_TYPE." -> "; //输出常量BOOK_TYPE
echo $c_book -> getObjectName(); //调用方法getObjectName
?>
</body>
</html>