admin 发表于 2020-10-22 15:11

php析构方法使用

当对象销毁的时候自动调用语法function __destruct(){
}脚下留心:析构函数不可以带参数代码运行案例:<?php
class Student {
        private $name;
        //构造方法
        public function __construct($name) {
                $this->name=$name;
                echo "{$name}出生了<br>";
        }
        //析构方法
        public function __destruct() {
                echo "{$this->name}销毁了<br>";
        }
}
//测试
$stu1=new Student('tom');
$stu2=new Student('berry');
$stu3=new Student('ketty');
echo '<hr>';
页: [1]
查看完整版本: php析构方法使用