Re: More than one values returned?

From: Date: Wed, 20 Feb 2008 15:24:43 +0000
Subject: Re: More than one values returned?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-269723@lists.php.net to get a copy of this message
On Mon, Feb 18, 2008 at 9:06 PM, Nick Stinemates <nick@stinemates.org> wrote: > 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. and this is what i was responding to earlier, nick, although you didnt criticize pass-by-reference directly you essentially said use of it indicates bad design, which i disagree with. check my post where i show a method with a boolean return value that has a pass-by-reference parameter to return data; that is a perfectly reasonable use case for pass-by-reference and it does not indicate bad design. nor would it, if there were more pass-by-reference parameters in that method. and here is another reason you might have to return more than on value from a method; a function needs to return data of different types. now php is loosely typed, so packaging these into an array is a joke, but in other languages, that are strongly typed, its not quite that simple. any way, when i think about a method returning a class, what if for whatever reason, a method were to return objects of 2 classes ? do you then create another class just for the purpose of packaging those 2 objects for this method to return a single value? well ill let you be the judge of that, but i would probly toss them in a small array, or, depending on the scenario, use pass-by-reference, especially if i wanted to return a boolean value from the method ;) -nathan

« previous php.general (#269723) next »