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();
?>
//创建类
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();
?>
相关文章推荐
- 微信网页授权(OAuth2.0) PHP 源码简单实现
- 微信网页授权(OAuth2.0)PHP 源码简单实现
- PHP实现简单聊天室(附源码)第1/2页
- 微信网页授权(OAuth2.0) PHP 源码简单实现
- EJB分布式远程调用的小例子的简单实现。[附源码]
- 简单的php+mysql聊天室实现方法(附源码)
- 简单的php+mysql聊天室实现方法(附源码)
- PHP实现简单聊天室(附源码)第1/2页
- 简单的php+mysql聊天室实现方法(附源码)
- html表单配合php实现一些简单功能的例子
- php结合表单实现一些简单功能的例子
- php结合表单实现一些简单功能的例子
- PHP实现文件上传的例子(附详细源码)
- PHP实现文件上传的例子(附详细源码)
- php实现socket简单的例子
- PHP实现鞍点数简单小例子
- 微信网页授权(OAuth2.0) PHP 源码简单实现
- html表单配合php实现一些简单功能的例子
- php投票系统简单实现源码(1/3)
- PHP大转盘抽奖简单实现例子