Hi,
Friday, February 28, 2003, 4:24:54 PM, you wrote:
AS> so i have a function that creates objects (with member variables) and
AS> pushes those objects onto the array. after adding all of the objects,
AS> the function then returns the array...
AS> i'm having trouble accessing the members of each object in the
AS> array...i'm trying to do something like this:
AS> class Object {
AS> var $id;
AS> function Object($param) {
AS> $this->id = $param;
AS> }
AS> }
AS> function getArrayOfObjects() {
AS> $theArray = array();
AS> for ($i = 0; $i < 10; $i++) {
AS> $theArray[] = new Objects($i);
AS> }
AS> return $theArray;
AS> }
AS> $temp = getArrayOfObjects();
echo $temp[0]->>id; // this should display "0"
AS> do i have to do something with references or dereference the id
AS> variable some other way? i'm coming from java where something like this
AS> is extremely easy...
AS> thanks
AS> amit
Try like this (note the 2 & symbols)
function &getArrayOfObjects() {
$theArray = array();
for ($i = 0; $i < 10; $i++) {
$theArray[] =& new Objects($i);
}
return $theArray;
}
$temp = getArrayOfObjects();
echo $temp[0]->id;
--
regards,
Tom
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php