[php]代码库
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>访问成员变量</title>
</head>
<body>
<?php
class MyObject{
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 $c_book -> object_name."<br>"; //调用输出变量$object_name
echo $c_book -> getObjectName(); //调用方法getObjectName
?>
</body>
</html>