i'm wondering if this is generally a bad idea...
<?
class test {
var $var1;
var $var2;
function Set($varname,$value) {
$this->$varname=$value;
}
}
$fanks = new test;
$fanks->Set('var1','foo');
$fanks->Set('var2','bar');
$fanks = new test;
$fanks->Set('var1','hello world');
echo "{$fanks->var1} {$fanks->var2}";
?>
it seems once i create the second instance, the namespace is totally wiped - ie: this will only print "hello world", rather than "hello world bar".
i guess i'm a bit curious as to what's actually going on here. is the original object simply destroyed and replaced with this?
of course i don't need to have a same-named instance, that's not a big deal, but i'm wondering if there's an equivalent of class_exists() for instances. object_exists(), or something of that nature.
mainly i just would rather not have a billion objects all holding variables if i can append to (or reset) objects. often i'm creating new objects inside a function, and tracking if i've already opened the object in a previous function is a lot of architectural flow work i'd like to avoid if possible. 😛
(i suppose i should nest more of the functions into the classes they address and make better use of $this->var, etcetera.)
a $connection->queryString() function is a prime example, since i can reuse the same object namespace and just forget about it.
then again i dunno, i'm an intermediate level developer at best and probably going down the same OOP pitfall that most people in my learning level do, namely using classes largely for a big treasure trunk of vars and functions... is it that horrible to have a dozen instances all open at once?