删除整个PHP类 [英] Deleting entire PHP Class

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

问题描述

class foo{
    ....
}

假设该类存在于我的代码中,然后稍后不再需要该类并希望将其删除(因此以后可以将其替换为新类)

Say that class exists in my code, then later on I no longer need this class and wish to remove it (so I can replace it with a new class later)

是否可以从运行时删除整个类?

Is it possible to delete an entire class from run time?

推荐答案

使用unset($ classVariableName)删除实例,它将释放内存.

Use unset($classVariableName) to delete the instance and it will free the memory.

如果该类的定义在运行时不存在,则需要将该类添加到单独的文件中,并且仅在需要时才包含该文件.这样您就可以拥有两个具有相同类名的不同类定义.但是,使用两个具有相同名称的不同定义不是一个好方法.

If the definition of the class shouldn't be there at run-time, then the class needs to be added in separate file and the file should be included only when it is require. So that you can have two different class definition with same class name. But having two different definition with same name is not a good way to go.

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

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