Re: Properly handling multiple constructors.

From: Date: Wed, 24 Mar 2010 15:51:50 +0000
Subject: Re: Properly handling multiple constructors.
References: 1 2 3 4 5 6 7 8 9  Groups: php.general 
Request: Send a blank email to php-general+get-303329@lists.php.net to get a copy of this message
Richard Quadling wrote:
On 24 March 2010 15:27, Robert Cummings <robert@interjinn.com> wrote:
Are you asking a question? I'm not sure what you want here :) Does the technique I sent provide you with a solution to this problem or not?
I can certainly see how your suggestion works. And in my own code, I've often misused a method param list like this, but that code never leaves my scratch area and is hardly ever documented (ok, I'll be honest - there is nothing in the scratch area which is documented!). Does having static methods to funnel to the main constructor (which is really always the complex one) make more sense here? That way it is self contained and no need to have any misuse and no additional classes. static function GetConnectorUsingKey($Key) {} static function GetConnectorUsingPartialData($Part1, $Part2, $Part3) {} static function GetConnectorUsingRules(Zend_Config $Rules) {} each returning a new DataConnector(). This looks easy to understand. The main constructor doesn't need to be hidden (GetConnectorUsingRules() is a static alias of __construct()). All looks ok?
Yes you can do that also, you seemed to want constructors though :) As for misused... variable parameters with mixed types is common enough that I wouldn't call it misuse. It's succinct and solves a problem. Look at the printf() family of functions. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP

« previous php.general (#303329) next »