RE: array of objects, how ?
| From: | Tim Ward | Date: | Mon, 18 Dec 2000 12:30:14 +0000 |
| Subject: | RE: array of objects, how ? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-30856@lists.php.net to get a copy of this message | ||
why not just ...
$my_array[$i] = new item(/*parameters*/);
... this should work. it sounds like you are creating 10 pointers to the
same object, which you are redefining in each loop.
Tim Ward
Senior Systems Engineer
Please refer to the following disclaimer in respect of this message:
http://www.stivesdirect.com/e-mail-disclaimer.html
> -----Original Message-----
> From: Jambet, Guillaume [mailto:Guillaume.Jambet@xrce.xerox.com]
> Sent: 15 December 2000 18:21
> To: 'php-general@lists.php.net'
> Subject: array of objects, how ?
>
>
> Hello, i`m trying to make an array of object in php4 and
> don`t succed :(
>
> is it possible ?
> has someone ever done / used one ?
> thanks !!!
>
> Guillaume.
>
> here is my code :
>
> var $my_array;
>
> function LoadArray(){
>
> global $my_array ;
>
> for ($i = 0 ; $i < 10 ; $i++){
> $tmp_item= new item(/*parameters*/);
> $my_array[$i] = $tmp_item;
> }
> }
>
>
> it seems to work but if i display the content of $my_array i have ten
> times the last one ...
>
> more if i try to display $my_array[$i-1] after storing $my_array[$i] i
> obtain $my_array[$i] ...
>
> thank you :)))
>