析构方法__destruct()释放内存,销毁对象,类最后自动执行(PHP基础教程)
- <?php
- class ZhaoPin{
- public $name;
- public $age;
- public $sex;
- public $height;
- //构造方法
- function __construct($name,$age,$sex,$height){ //自动执行 构造方法 初始化对象
- $this->name = $name;
- $this->age = $age;
- $this->sex = $sex;
- $this->height = $height;
- }
-
- function ziDiu(){
- if($this->age >18 && $this->height >160){
- return $this->name .'符合招聘条件。';
- }else{
- return $this-name .'不符合招聘条件';
- }
- }
- //析构方法 释放内存 销毁对象 类最后自动执行
- function __destruct(){
- unset($ziDiuZhaoPin);
- echo '释放完毕。';
- }
- }
- $ziDiuZhaoPin = new ZhaoPin('自丢','26','男','178');
- echo $ziDiuZhaoPin->ziDiu().'<br>';
复制代码 PHP源码运行结果图:
析构方法__destruct()释放内存,销毁对象,类最后自动执行(PHP基础教程)
|