Re: Array of Classes
| From: | Rob Wiltbank | Date: | Mon, 06 Oct 2003 18:38:33 +0000 |
| Subject: | Re: Array of Classes | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-165227@lists.php.net to get a copy of this message | ||
Cheers! Just what I was looking for. :)
Rob
"David Otton" <phpmail@jawbone.freeserve.co.uk> wrote in message
news:s9c3ov4h86vtj355m0h9hbf7tm6a2e4bgh@4ax.com...
> On Mon, 6 Oct 2003 13:41:22 -0400, you wrote:
>
> >1) How can I create an array of classes so they could be referenced, for
> >instance: $array[$uniqueID][$class->var] = 10; ?
> >
> >2) Would it instantiate when that particular element was used and would
the
> >constructor run at that point?
> >
> >3) Any way to dispose/destroy of an object once it's done being used to
free
> >up the resources?
>
> <?
>
> class A {
> function A () {
> echo ("<p>Created</p>");
> }
>
> function B ($s = "None") {
> echo ("<p>input : $s</p>");
> }
> }
>
> $C = array();
>
> for ($i = 0; $i < 3; $i++)
> {
> $C[$i] = new A();
> }
>
> for ($i = 0; $i < 3; $i++)
> {
> $C[$i]->B($i);
> }
>
> for ($i = 0; $i < 3; $i++)
> {
> unset ($C[$i]);
> }
>
> ?>