List Info

Thread: note 61849 added to language.references.pass




note 61849 added to language.references.pass
user name
2006-02-13 19:42:24
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?
----
Server IP: 64.71.164.2
Probable Submitter: 139.76.128.68
----
Manual Page -- http://www.php.net/manual/en/language.references.pass.p
hp
Edit        -- http://master.php.net/manage/user-notes.php?action=
edit+61849
Delete: added to the manual -- htt
p://master.php.net/manage/user-notes.php?action=delete+61849
&report=yes&reason=added+to+the+manual
Delete: bad code            -- http://master.
php.net/manage/user-notes.php?action=delete+61849&report
=yes&reason=bad+code
Delete: spam                -- http://master.php.
net/manage/user-notes.php?action=delete+61849&report=yes
&reason=spam
Delete: useless             -- http://master.p
hp.net/manage/user-notes.php?action=delete+61849&report=
yes&reason=useless
Delete: non-english         -- http://mast
er.php.net/manage/user-notes.php?action=delete+61849&rep
ort=yes&reason=non-english
Delete: already in docs     -- http://
master.php.net/manage/user-notes.php?action=delete+61849&
;report=yes&reason=already+in+docs
Delete: other reasons       -- http://master.php.net/manage/user-
notes.php?action=delete+61849&report=yes
Reject      -- http://master.php.net/manage/user-
notes.php?action=reject+61849&report=yes
Search      -- http://ma
ster.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php

note 61849 rejected from language.references.pass by nlopess
user name
2006-02-13 20:00:17
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?

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )