Re: Re: Your opinion about QuickForm2 API
| From: | Alexey Borzov | Date: | Mon, 16 Apr 2007 17:39:10 +0000 |
| Subject: | Re: Re: Your opinion about QuickForm2 API | ||
| References: | 1 2 | Groups: | php.pear.dev php.pear.general |
| Request: | Send a blank email to pear-dev+get-46259@lists.php.net to get a copy of this message | ||
Hi,
Justin Patrin wrote:
To summarize, Alexey would be in favor of this: $form->addElement('button', 'aButton', 'Click me please'); $form->addElement('select', 'aSelect', array('1' => 'option 1', '2' => 'option 2'));Well, this has worked in the past and isn't too hard to grasp if the documentation makes it clear how this works (the current docs are a bit confusing in this regard). Having the additional parameters be the constructor args for the element is a fine option. However, it's always confusing to have lots of parameters to a method and I know I never remember which is which.
Well, people aren't yet familiar with the new QF2 API and Bertrand didn't bother to give the full picture, so here goes: We no longer have variable number of parameters to elements' constructors, since neither Bertrand nor myself were able to remember all the parameter lists, and we actually *wrote* the abomination. Every constructor is now defined as: public function __construct($name, $data, $label, $attributes) { ... } Now, this what this $data thing means changes from element to element because the elements have different needs. What's *really* being discussed here is the fact that Bertrand wants to make $data *always* an associative array, thus $form->addElement('button', 'aButton', array('content' => 'Click me please')); $form->addElement('select', 'aSelect', array('options' => array('1' => 'option 1', '2' => 'option 2'))); while I suggest deciding on it on a per-element basis, thus $form->addElement('button', 'aButton', 'Click me please'); $form->addElement('select', 'aSelect', array('1' => 'option 1', '2' => 'option 2')); but most certainly $form->addElement('year', 'aYear', array('startYear' => '2007')); since that hypothetical 'year' element *may* earn additional parameters in the future which is highly unlikely in case of Buttons and Selects.$form->addElement('year', 'aYear', '2007'); While I would use: $form->addElement('year', 'aYear', array('startYear' => '2007')); So my way is more verbose and less writable, but is also more readable and extensible.Extensability is a good thing. Readability is a good thing. I'd vote for an assoc array over variable numbers of arguments.