PHP简单的类实现例子源码

<?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();
?>

原文地址:https://www.cnblogs.com/zhongbin/p/2871951.html