您的位置:首页 > 编程语言 > PHP开发

PHP简单的类实现例子源码

2013-01-22 19:26 483 查看
<?php
//创建类
class HelloWorld{
//受保护的成员变量
protected $helloWord;
//构造函数 类实例化初始化类成员变量
public function __constructor($helloWord){
$this->helloWord=$helloWord;
}
//类成员方法
public function getHtml(){
retrun "<html><body>This is {$this->helloWord}</body></html>";
}
//释放类成员变量
public function freeResult(){
$this->helloWord='';

}
//析构函数
public function __destructor(){
$this->freeResult();
}
}

//类实例化 创建对象
$test=new HelloWord('Hello Word!');
//对象调用成员方法
$test->getHtml();
$this->freeResult();
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: