Redeclaring or Deleting a Class object

Associate
Joined
18 Oct 2002
Posts
2,367
Hi Guys

Hopefully you can help. If I declare a class in PHP like this:

$class = new Class

If I wanted to delete this class how would I do it?

Phil
 
Soldato
Joined
18 Oct 2002
Posts
5,464
Location
London Town
Just to be pedantic, the variable $class is not a class. It's an object, which is an instance of a class.

Depends what you mean by 'delete'. Just using unset($class) should do.
There are specific magic methods for doing things when you destroy an instance, e.g. unsetting particular properties, running cleanup functions, if that's what you're after.
 
Associate
OP
Joined
18 Oct 2002
Posts
2,367
Yeah i have tried unset but it wont seem to remove it. What I have is this:

white loop {
file is required with class in
functions within that class are executed
}

Now each time the while is run a different file is required, but within each of the files, I have the same class name. I have tried unset before the while loops to the next round but it still insists that the class has already been declared, even tho I unset it.
 
Soldato
Joined
18 Oct 2002
Posts
5,464
Location
London Town
I'm not sure I entirely follow what you're doing. it appears the problem is related to the actual class declaration being included more than once, not the instantiation.

Use require_once() or include_once() to ensure the file that contains your class declaration isn't evaluated more than once in the script's execution.
 
Back
Top Bottom