Re: OO Question for PHP4

From: Date: Wed, 11 Aug 2004 16:17:10 +0000
Subject: Re: OO Question for PHP4
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-193465@lists.php.net to get a copy of this message
On Wed, 2004-08-11 at 11:14, Jed R. Brubaker wrote: > Hi all. As the subject suggests, I am using PHP4 and am having something > going on that I don't think should be. > > Presume the following code > class Foo { > function Foo () { > return "Bar"; > } > } > $foo = new Foo; > echo $foo; > > $foo comes out as an object. Does this have to be done in two line like > this?: > class Foo { > function bar () { > return "Bar"; > } > } > $foo = new Foo; > $bar = $foo->bar; > > Or is there a better design approach I should be reminded of or learn? > > Thanks in advance! Constructors always return a reference to the object. A return statement is disregarded. Have a look at http://www.php.net/language.oop.constructor in particular a post in the comments by steffen staehle. HTH -- Regards, David GetAnyIdeas Web Design php@getanyideas.com P. 416.452.9410 F. 416.570.4529

« previous php.general (#193465) next »