Objects & arrays??
| From: | David Reid | Date: | Sun, 11 Jun 2000 22:47:16 +0000 |
| Subject: | Objects & arrays?? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-1574@lists.php.net to get a copy of this message | ||
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."