Removing an entire PHP class

class foo{ .... } 

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

Is it possible to remove the entire class from runtime?

+6
source share
3 answers

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

If the class definition should not be present at run time, then the class should be added to a separate file, and the file should be included only when required. That way you can have two different class definitions with the same class name. But having two different definitions with the same name is not the best way to go.

+2
source

No, you cannot remove or substantially modify PHP classes (or functions) at run time.

+7
source

You can use unset () to delete an object, but the class itself cannot be deleted. Honestly, modifying code like this at runtime sounds silly and confusing - is there a better option?

+1
source

Source: https://habr.com/ru/post/920767/


All Articles