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

Bug #80 HTML_QuickForm::addElement($element) dosen't pass by reference
Submitted: 2003-10-08 20:08 UTC
From: marba126 at student dot liu dot se Assigned:
Status: Wont fix Package: HTML_QuickForm
PHP Version: Irrelevant OS: Windows 98 SE
Roadmaps: (Not assigned)    
Subscription  
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes. If this is not your bug, you can add a comment by following this link. If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
2003-10-09 10:14 UTC
Package:
Bug Type:
Summary:
From: marba126 at student dot liu dot se
New email:
PHP Version: Package Version: OS:

 

 [2003-10-08 20:08 UTC] marba126 at student dot liu dot se
Description: ------------ Unexpected beaviour: using $element->setValue(), after $element has been added to the form with addElement($element), will have no effect. This is probably because addElement() dosen't pass by reference. Thus addElement() creates a copy of the element you added (which will not be affected when you change the origin element). HTML_QuickForm ver. 3.1.1 Reproduce code: --------------- <?php require_once ("HTML/QuickForm.php"); $form = new HTML_QuickForm(); $text =& $form->createElement('text', 'testText', 'This should be "Set after addElement() call" :', 'size=40'); $text->setValue("Set before addElement() call"); $form->addElement($text); $text->setValue("Set after addElement() call"); $form->display(); ?> Expected result: ---------------- The value of the text input field is expected to be "Set after addElement() call" when form is displayd. Actual result: -------------- The value of the text input field is "Set before addElement() call" when form is displayd.

Comments

 [2003-10-09 07:51 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2003-10-09 09:59 UTC] marba126 at student dot liu dot se
I just got a brigth idea (that seems to work). However it's a workaround rather than a fix. It's a much better to call addElement(&$element) - note '&'! This might be worth a note in the manual because the "fix" presented by avb@php.net isn't always applicable. (In a future version of PHP maybe this can be fixed with method overloading?) <?php require_once ("HTML/QuickForm.php"); $form = new HTML_QuickForm(); $text =& $form->createElement('text', 'testText', 'This should be "Set after addElement() call" :', 'size=40'); $text->setValue("Set before addElement() call"); $form->addElement(&$text); $text->setValue("Set after addElement() call"); $form->display(); ?>
 [2003-10-09 10:14 UTC] mansion at php dot net
Wrong. Doing that will throw a call time pass by reference warning. You should always develop your code with error_reporting(E_ALL); Alexey's suggestion is the way to go.