cascading class wierdness?
| From: | Shannon Weyrick | Date: | Wed, 11 Aug 1999 16:48:39 +0000 |
| Subject: | cascading class wierdness? | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-3341@lists.php.net to get a copy of this message | ||
hi,
came across this whilst playing with some more OO stuff. the following script
appears to die after reaching the definition of class testClass - by die, I
mean, no code is executed at ALL after it's definition, no errors are
reported, and the server returns "Document Contained No Data". Where I have the
phpinfo() call in there now, never gets executed. if I uncomment that call
directly BEFORE the testClass class definition, however, php info comes back as
normal (but the rest of the script doesn't run).
the code might or might not be all that practical, but I dont think it's
invalid code. but, perhaps I'm missing something?
<?
class arrayClass {
var $myArray;
function add($key, $val) {
$this->myArray[$key] = $val;
}
function output() {
echo "size of myArray is
".sizeof($this->myArray)."\n\n<br><br>";
foreach($this->myArray as $k => $v) {
echo "$k => $v<br>\n";
}
}
}
/* putting this call here would execute php info correctly */
/* phpinfo(); */
/* execution aborts after compiling this class?? */
class testClass {
var $myArrayClass;
/* constructor ... */
function testClass() {
$this->myArrayClass = new arrayClass;
}
}
/* the script never reaches this point, the server simply returns
document contained no data */
phpinfo();
class mainClass {
var $myTestClass;
function newClass() {
$this->myTestClass = new testClass;
return $this->myTestClass->myArrayClass;
}
function output() {
$this->myTestClass->myArrayClass->output();
}
}
$myMainClass = new mainClass;
$arrayTestClass = $myMainClass->newClass();
$arrayTestClass->add("test1","val1");
$arrayTestClass->add("test2","val2");
$myMainClass->output();
?>
<!-- this is the end of the script -->
--
shannon weyrick (weyrick@roadsend.com),
sysadmin/programmer