I have a class and I would like to create a function to clear all variables within the object, regardless of how many variables are added or taken out. Something like this..
class object()
{
$a;
$b;
$c;
function clear_data()
{
foreach(variable in this object)
variable = null;
}
}
Don't think that was quite what I was looking for. The reason I was looking for a way to clear all variables in an object is this. The object has a function called load, that just loads a bunch of data from the DB. If while loading, it finds a bad piece of data, I want it to clear all the variables within the object.
I could make a function called clear() and just have it do something like:
<?php
class Foo
{
public $a;
public $b;
public function clearAllVars()
{
$vars = get_object_vars($this);
foreach($vars as $key => $val)
{
$this->$key = null;
}
}
}
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks