We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
当类被实例化的时候,构造方法调用
用于实例化类的时候初始化相关数据。
// 构造方法语法格式 [修饰符] function__construct([参数]){ 程序体 }
当类不用再使用这个类里面的属性和方法的时候,析构方法执行。
可以禁用资源的释放:数据库关闭、读取文件关闭等等,对象被销毁的时候执行,也就是说这个对象没有代码再运行了。
//析构方法方法格式 [修饰符] function__destruct([参数]){ 程序体 }
class Test { //构造方法 public function __construct($name , $age){ echo 'hello'.$name; echo"</br>"; $this -> age =$age; $this -> name = $name; } public function data(){ return $this -> age; } //析构方法。 public function __destruct(){ echo "bye bye {$this -> name}"; } } $test = new Test('first',20); $test = new Test('first',20); //对象的执行顺序----先进先出 // echo $test -> data(); //输出20
The text was updated successfully, but these errors were encountered:
No branches or pull requests
构造方法
当类被实例化的时候,构造方法调用
构造方法的用途
用于实例化类的时候初始化相关数据。
析构方法
当类不用再使用这个类里面的属性和方法的时候,析构方法执行。
析构方法的用途
可以禁用资源的释放:数据库关闭、读取文件关闭等等,对象被销毁的时候执行,也就是说这个对象没有代码再运行了。
构造方法与析构方法的实例
The text was updated successfully, but these errors were encountered: