请选择 进入手机版 | 继续访问电脑版

析构方法__destruct()释放内存,销毁对象,类最后自动执行(PHP基础教程)

[复制链接]
查看3020 | 回复1 | 2019-3-25 09:58 | 显示全部楼层 |阅读模式
析构方法__destruct()释放内存,销毁对象,类最后自动执行(PHP基础教程)
  1. <?php
  2. class ZhaoPin{
  3.         public $name;
  4.         public $age;
  5.         public $sex;
  6.         public $height;
  7.         //构造方法
  8.         function __construct($name,$age,$sex,$height){   //自动执行 构造方法 初始化对象
  9.                 $this->name = $name;
  10.                 $this->age = $age;
  11.                 $this->sex = $sex;
  12.                 $this->height = $height;
  13.         }
  14.         
  15.         function ziDiu(){
  16.                 if($this->age >18 && $this->height >160){
  17.                         return $this->name .'符合招聘条件。';
  18.                 }else{
  19.                         return $this-name .'不符合招聘条件';
  20.                 }
  21.         }
  22.         //析构方法   释放内存 销毁对象 类最后自动执行
  23.         function __destruct(){
  24.                 unset($ziDiuZhaoPin);
  25.                 echo '释放完毕。';
  26.         }
  27. }

  28. $ziDiuZhaoPin = new ZhaoPin('自丢','26','男','178');
  29. echo $ziDiuZhaoPin->ziDiu().'<br>';
复制代码
PHP源码运行结果图:

析构方法__destruct()释放内存,销毁对象,类最后自动执行(PHP基础教程)

析构方法__destruct()释放内存,销毁对象,类最后自动执行(PHP基础教程)

乐乐 | 2019-8-20 05:44 | 显示全部楼层
自丢网真心不错,学习教程网。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

UID
1
贡献
387
丢币
38902
主题
4607
回帖
116
注册时间
2018-9-25
最后登录
2024-3-24