I need some help. I have a working class and I can use a foreach() to display the public variables:
class MyClass {
public $a;
public $b;
function __construct($aX,$bX){
$this->a = $aX;
$this->b = $bX;
}
}
$class = new MyClass(3,5);
foreach($class as $key => $value) {
print "$key => $value</br>\n";
}
produces:
a => 3
b => 5
Now my problem arises when I want to have an array of MyClass:
class MyClass
{
public $a;
public $b;
function __construct($aX,$bX){
$this->a = $aX;
$this->b = $bX;
}
}
$class = array(
"odd"=>new MyClass(3,5),
"even"=>new MyClass(2,4)
);
foreach($class as $key => $value) {
print "$key => $value</br>\n";
}
produces:
Catchable fatal error: Object of class MyClass could not be converted to string...
How can I loop through the all the elements of the $class array? Any help would be great!