PHP的 - 取消$这个 [英] php - unset $this

查看:122
本文介绍了PHP的 - 取消$这个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个类似文件包装的类。当用户调用delete方法时,我想取消设置对象(实际上是$ this)。有没有办法(解决方法)来做到这一点?该手册说不,没有办法...

解决方案

据我所知,没有办法摧毁一个从类本身内部的类实例。

  $ myClass = new fooBar(); 
unset($ myClass);

有点相关:做以上操作会自动调用任何现有的 __ destruct()类的魔术方法,所以你可以做任何额外的清理。 更多信息


I've made a class that acts like an file wrapper. When user call delete method, i want to unset the object (actually $this). Is there a way (workaround) to do that? The manual said no, there is no way...

解决方案

As far as I know, there is no way to destroy a class instance from within the class itself. You'll have to unset the instance within its scope.

$myClass = new fooBar();
unset($myClass);

Somewhat related: Doing the above will automatically call any existing __destruct() magic method of the class so you can do any additional cleanup. More info

这篇关于PHP的 - 取消$这个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆