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?
To delete a file in PHP, use the unlink function. Let's go through an example to see how it works. The first argument of the unlink function is a filename which you want to delete. The unlink function returns either TRUE or FALSE , depending on whether the delete operation was successful.
There is no delete() function in PHP. If you need to delete a file, look at the unlink() function.
There is no delete keyword or function in the PHP language. If you arrived at this page seeking to delete a file, try unlink(). To delete a variable from the local scope, check out unset().
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With