Reputation: 873
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?
Upvotes: 11
Views: 15721
Reputation: 2356
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.
Upvotes: 5
Reputation: 397
You can use unset() to delete an object, but the class itself cannot be deleted. To be honest, modifying code like that at runtime sounds kludgy and confusing - is there not a better option?
Upvotes: 2
Reputation:
No, you cannot delete or substantially modify PHP classes (or functions) at runtime.
Upvotes: 8