[PHP] OO Question for PHP4
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! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] OO Question for PHP4
[snip] 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; [/snip] This is correct. $foo = new Foo; // calls $foo as the object echo $foo; // echo's an object Bar would then be a public member of $foo, hence $foo-bar. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OO Question for PHP4
Im sure you should be returning a value in your constructor at all?? Ill check the manual, but i dont think ive ever seen a constructor return anything, doesnt sound right.. Let me check. Jason Jed R. Brubaker [EMAIL PROTECTED] 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! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OO Question for PHP4
* Jason Davidson [EMAIL PROTECTED]: Im sure you should be returning a value in your constructor at all?? Ill check the manual, but i dont think ive ever seen a constructor return anything, doesnt sound right.. Let me check. From my experience, returning a value from a constructor currently does nothing, in either PHP4 or PHP5. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OO Question for PHP4
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 [EMAIL PROTECTED] P. 416.452.9410 F. 416.570.4529 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OO Question for PHP4
Yup, i typo'd .. should have read, Im not sure you should be returning a value.. Jason Matthew Weier O'Phinney [EMAIL PROTECTED] wrote: * Jason Davidson [EMAIL PROTECTED]: Im sure you should be returning a value in your constructor at all?? Ill check the manual, but i dont think ive ever seen a constructor return anything, doesnt sound right.. Let me check. From my experience, returning a value from a constructor currently does nothing, in either PHP4 or PHP5. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OO Question for PHP4
On Wed, 11 Aug 2004 09:14:08 -0600, Jed R. Brubaker [EMAIL PROTECTED] 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-- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php