phpStrom 里alt+insert 会出现的一些函数
析构函数destruct

简单理解:构造函数的对立面
构造函数:__construct()在初始化对象的时候默认执行的
析构函数:__destruct()在对象销毁回收时候默认执行的,类似于web框架里面的钩子函数
触发条件 当对象或者变量 消失时候
关键词:unset或者对象生命周期结束
phpStrom 里alt+insert 会出现的一些函数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| calss A{ protected $data = [];
public function insert($data) { $data['appkey'] = getAppkey(); $data['channel'] = getChannel(); $this->data[] = $data; //这个[]意思在多个多次调用的时候插入整个数组很关键,可以看下面内容 请求中 php 如何分配phpfpm } public function __destruct() { if ($this->data) { $this->getDB()->insert_batch($this->table, $this->data); $id = $this->getDB()->insert_id(); Ioc()->CallRecordModel->_delete([ 'id <' => $id - 50000 ], '', 1000); } } }
$zend=new A(); $zend->insert(["aaaaa"]);
|