To get what you want you need to use following syntax:
print_r($class->foo);
The __toString() magic method tries to convert your whole class 'TestClass' to a string, but since the magic method is not returning a string, it is showing you that error. Of course you could also rewrite your __toString() method to do the following:
public function __toString()
{
return print_r($this->foo, true);
}
http://php.net/manual/en/function.print-r.php
http://www.php.net/manual/en/language.oop5.magic.php#object.tostring