Re: Objects & arrays??
| From: | Rasmus Lerdorf | Date: | Mon, 12 Jun 2000 01:38:22 +0000 |
| Subject: | Re: Objects & arrays?? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-1583@lists.php.net to get a copy of this message | ||
It would help if you would describe exactly what you think is not doing
what you think it should. The output from your script is:
This is A!
Hello - B!!!
<hr>
Hello - B!!!
Hello - C aa!!!
Hello - C cc!!!
Now, what do you think it should be?
On Sun, 11 Jun 2000, David Reid wrote:
> I've just started playing with classes to hold information for a project,
> but I've run into some weirdness!
>
> This is a test script I wrote to make sure I wasn't going mad...
>
> <?
> class a {
> var $b;
> var $bcount = 0;
>
> function AddB($newb)
> {
> $this->b[$this->bcount++] = $newb;
> }
> function PrintTree()
> {
> print "This is A!\n";
> for ($i=0;$i < $this->bcount; $i++) {
> $this->b[$i]->PrintHello();
> }
> }
> }
>
> class b {
> var $c;
> var $ccount = 0;
>
> function AddC($newc)
> {
> $this->c[$this->ccount++] = $newc;
> }
>
> function PrintHello()
> {
> print "Hello - B!!!\n";
> for ($i=0;$i < $this->ccount;$i++) {
> $this->c[$i]->PrintHello();
> }
> }
> }
>
> class c {
> var $str;
>
> function PrintHello()
> {
> print "Hello - C ".$this->str."!!!\n";
> }
> }
>
> $start = new a;
> $next = new b;
> $start->AddB($next);
>
> $aa = new c;
> $aa->str = "aa";
> $next->AddC($aa);
> $ab = new c;
> $ab->str = "cc";
> $next->AddC($ab);
>
> $start->PrintTree();
> echo "<hr>\n";
> $next->PrintHello();
> ?>
>
> So can structures only be nested 2 deep or am I doing something really wrong
> here?
>
> All help appreciated. I'm not subscribed but will check in a day or so...
> Thanks.
>
> david
>
> "Do not meddle in the affairs of sysadmins, they are quick to
> anger and have no need for subtlety."
>
>
>
>