Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.3.2

Request #15618 [patch] support arrayAccess interface
Submitted: 2009-01-12 15:28 UTC
From: cybot Assigned:
Status: Open Package: HTML_QuickForm2 (version CVS)
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  


 [2009-01-12 15:28 UTC] cybot (Sebastian Mendel)
Description: ------------ These patch implements arrayAccess Interface into HTML_QuickForm2_Container

Comments

 [2009-01-12 15:41 UTC] cybot (Sebastian Mendel)
very short incomplete example usage: $form['container'] = array('fieldset'); $form['container']['element_id'] = array('text'); echo $form['element_id']; echo $form['container']['element_id']; unset($form['container']); with Smarty: {$form.element_id} {$form.container.element_id}
 [2011-11-07 23:24 UTC] cweiske (Christian Weiske)
I'd love to see this.
 [2011-11-08 02:42 UTC] mansion (Bertrand Mansion)
I like this too, but we have to check for side cases first. With ArrayAccess, things can get ugly.
 [2012-04-02 02:48 UTC] avb (Alexey Borzov)
If we are trying to mimic SimpleXML here, then we probably should use ArrayAccess for attributes (and that should be implemented in HTML_Common2). Also note that SimpleXML itself allows $xml->foo = 'bar'; only for text content, you still have to do $xml->foo->addChild('bar', 'text'); to add a child element. We generally don't do text content in QF2 and semantics of $form->foo = array('bar') are difficult to understand, IMO. Are we adding element of type 'bar' named 'foo' or vice versa? What happens if form already contains element named 'foo' (or 'bar')? Current __call()-based methods $form->addBar('foo'); or $form->addFoo('bar'); are sufficiently short, IMO. And less confusing. I do think magic __get() / __isset() methods can be implemented as a shorthand for getElementById(), though. But let's keep this stuff read-only.
 [2012-04-02 03:04 UTC] cweiske (Christian Weiske)
I think the readonly stuff would suffice for most use cases.
 [2012-04-08 23:17 UTC] avb (Alexey Borzov)