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!
Objects in arrays - functions not accessible
Moderator: General Moderators
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
Yeah i do it all the time except i use named indexes in the array instead of just the indices.
Code: Select all
class foo {
var $hello = "boo";
function bar(){
echo $hello;
}
}
$objects - array();
$objects['foo'] - new foo();
$objects[foo']->bar();