Re: OO Question for PHP4

From: Date: Wed, 11 Aug 2004 17:34:11 +0000
Subject: Re: OO Question for PHP4
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-193479@lists.php.net to get a copy of this message
On Wed, 11 Aug 2004 09:14:08 -0600, Jed R. Brubaker <jrb21398@hotmail.com> 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"; You shouldn't be returning from a constructor. > } > } > $foo = new Foo; > echo $foo; It's generally bad prcative to echo anything other than scalar types (strings and numbers). Try using print_r() or var_dump() instead. > > $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; Yes, this has to be two lines. I'm not sure how you'd want to put this as one. In addition, you should have parenthesis on your funciton call: $bar = $foo->bar(); > > Or is there a better design approach I should be reminded of or learn? > -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin--

« previous php.general (#193479) next »