Objects in arrays - functions not accessible
Posted: Thu Jul 29, 2004 1:48 pm
I can't seem to access a class function when my objects are stored in arrays? I am new to PHP but not to OOP.
Example:
class foo
{
var $a;
var $b;
function f1() {
return "f1 function return";
}
}
I use the class in another php file...
$arrayOfFoos[3]=new foo;
$arrayOfFoos[3]->a="the value of variable a for this object";
I then can use the variables values in this object...
print $arrayOfFoos[3]->a;
... which returns "the value of variable a for this object"
HOWEVER... when I call a function...
print $arrayOfFoos[3]->f1();
...I get "function not accessible".
In the SAME PHP I can use/access the function just fine if I do not put the object into an array. eg...
$ttt = new foo;
print $ttt->f1();
... works.
HELP??? Can objects functions be accessed if the object is stored in an array?? HOW??
THANKS!
Example:
class foo
{
var $a;
var $b;
function f1() {
return "f1 function return";
}
}
I use the class in another php file...
$arrayOfFoos[3]=new foo;
$arrayOfFoos[3]->a="the value of variable a for this object";
I then can use the variables values in this object...
print $arrayOfFoos[3]->a;
... which returns "the value of variable a for this object"
HOWEVER... when I call a function...
print $arrayOfFoos[3]->f1();
...I get "function not accessible".
In the SAME PHP I can use/access the function just fine if I do not put the object into an array. eg...
$ttt = new foo;
print $ttt->f1();
... works.
HELP??? Can objects functions be accessed if the object is stored in an array?? HOW??
THANKS!