I just tried the code that you posted, and it works fine, even without declaring the member variable.
Are you maybe doing something else? I wonder if you're not being bitten by the "copy on assignment" thing...
$x = new foo("aaa");
$y = $x; // $y is a clone, not the same instance!
$x->foovar = "bbb";
$y->printfoo(); // prints aaa
It can also get you with some language constructs, like foreach:
$a = new foo("aaa");
$b = new foo("bbb");
$c = new foo("ccc");
$objects = array($a, $b, $c);
foreach ($objects as $o) {
$o->foovar = "ddd";
$o->printfoo(); // prints "ddd"
}
foreach ($objects as $o) {
$o->printfoo(); // prints "aaa", "bbb", "ccc"
}
The solution is to always assign objects by reference (=& instead of =), and don't use foreach like that.