note 61849 rejected from language.references.pass by nlopess
| From: | nlopess@php.net | Date: | Mon, 13 Feb 2006 20:00:17 +0000 |
| Subject: | note 61849 rejected from language.references.pass by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-103642@lists.php.net to get a copy of this message | ||
Note Submitter: dishmael at windwardcg dot com
----
I'm still new to PHP so please bear with me. I have two simple classes:
class Foo {
private $Bars; // an array of Bar objects
function Foo() {
$this->Bars = array();
}
function addBar( &$bar ) {
array_push( $this->Bars, $bar );
}
function toString() {
while ( $bar = each( $this->Bars) ) {
echo $bar->toString() // this generates an error
}
}
}
class Bar {
function toString() {
return "Test";
}
}
$foo = new Foo();
$foo->addBar( new Bar() );
$foo->toString();
Which generates the following error:
Fatal error: Call to a member function toString() on a non-object in test.php
Can any of you PHP gurus point me to what I'm doing wrong?