Re: More than one values returned?
| From: | Robert Cummings | Date: | Tue, 19 Feb 2008 02:46:53 +0000 |
| Subject: | Re: More than one values returned? | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-269583@lists.php.net to get a copy of this message | ||
On Mon, 2008-02-18 at 18:29 -0800, Nick Stinemates wrote:
> Robert Cummings wrote:
> > On Mon, 2008-02-18 at 18:06 -0800, Nick Stinemates wrote:
> >
> >> C.R.Vegelin wrote:
> >>
> >>> <?php
> >>> $in = 4;
> >>> calcpows($in, $pow2, $pow4);
> >>> echo "in = $in pow2=$pow2 pow4=$pow4";
> >>>
> >>> // define return fields as &$...
> >>> function calcpows($in, &$pow2, &$pow4)
> >>> {
> >>> $pow2 = $in * $in;
> >>> $pow4 = $pow2 * $pow2;
> >>> }
> >>> ?>
> >>>
> >>> HTH
> >>>
> >>>
> >> Thats a good example, and a good reason for passing values by Reference
> >> instead of by Value.
> >>
> >> I have found, however, that if I ever need to return /multiple/ values,
> >> it's usually because of bad design and/or the lack of proper encapsulation.
> >>
> >
> > You mean you've never had a function like getCoordinates()? Or
> > getUsers(), or any other of a zillion perfectly valid and reasonable
> > functions that return multiple values as an array? Wow, how odd!
> >
> > Cheers,
> > Rob.
> >
> getCoordinates() would return a Point object
> getUsers() would return a Group object...
>
> Not rocket science ;)
I'd just return arrays unless I had a specific need for incurring object
overhead for such simple datatypes.
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com
|
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'