Hello,
what is wrong here? the purpose is to create an array of objects and then
interate over it,
calling some method from all of them.
I get just the following at the marked line ("// FATAL ERROR"):
Fatal error: Call to a member function on a non-object
See the code:
thank you for any hellpful hints!
<?php
$out="<h1>test for array input</h1><hr>";
$obj1=new Test ("FIRST");
$obj2=new Test ("SECOND");
$obj3=new Test ("THIRD");
//$array1=array($obj1, $obj2);
$array1[]=$obj1;
$array1[]=$obj2;
$out.="Listing with for: <br><br>";
for ($i=0;$i<sizeof ($array1);$i++)
{
$k=$array[$i];
$out.="calling name, i=$i: ".$k->toString(); // FATAL ERROR
}
class Test
{
var $name;
function Test ($name)
{
$this->name=$name;
}
function toString()
{
return "my name is: ".$this->name;
}
}
?>