This is a discussion on Class returning more than one value within the PHP General forums, part of the PHP Programming Forums category; Hi, How can i code a class with a function that returns more than one value ? Any help would be ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
On Sat, 2006-10-14 at 11:06 +0100, Deckard wrote: > How can i code a class with a function that returns more than one value ? > 1. return array(); 2. return stdClass; --Paul All Email originating from UWC is covered by disclaimer http://www.uwc.ac.za/portal/uwc2006/...imer/index.htm |
|
|||
|
Paul Scott wrote:
> On Sat, 2006-10-14 at 11:06 +0100, Deckard wrote: >> How can i code a class with a function that returns more than one value ? >> > > 1. return array(); > 2. return stdClass; > > --Paul > another option.. can be avoid, is to use global variables or references...and modify them in the function -- Thanking You Sumeet Shroff http://www.prateeksha.com Web Designers and PHP / Mysql Ecommerce Development, Mumbai India |
|
|||
|
Actually, probably the better way to keep variables seperate, is
reference variables. Using globals works, yes, but its not going to be as easy to read whats going on. http://us3.php.net/manual/en/languag...ences.pass.php Pass in a variable by reference, change the value bling bloop you get as many variables returned without having to write bad code. Bob Sumeet wrote: > Paul Scott wrote: > > On Sat, 2006-10-14 at 11:06 +0100, Deckard wrote: > >> How can i code a class with a function that returns more than one value ? > >> > > > > 1. return array(); > > 2. return stdClass; > > > > --Paul > > > > another option.. can be avoid, is to use global variables or > references...and modify them in the function > > -- > Thanking You > > Sumeet Shroff > http://www.prateeksha.com > Web Designers and PHP / Mysql Ecommerce Development, Mumbai India |
|
|||
|
On Sat, October 14, 2006 5:06 am, Deckard wrote:
> How can i code a class with a function that returns more than one > value ? Classes do not return values. Functions return values. Class methods (which are very much like functions) return values. In PHP, functions/methods do not return more than one value. You must wrap your multiple values up into some kind of more complex (non-scalar) structure. An array or an instance of a class will both work fine. Which one is appropriate depends on the existing application, framework, and personal religious convictions of code develoment. YMMV -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? |