Re: Possible Bug in Quickform / Select

From: Date: Sat, 09 Aug 2003 16:25:03 +0000
Subject: Re: Possible Bug in Quickform / Select
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-19444@lists.php.net to get a copy of this message
<pascalthuet@altern.org> wrote : > Hi all, > > I try to build a ComboBox with a 0 index eg . > > <select name="select" size="1"> > <option value="All" selected>All</option> > <option value=0 selected>No</option> > <option value=1>Yes</option> > </select> > > If I use the setSelected() Methode like this > > $selectElement->setSelected("All"); > > I get the following result > > <select name="select" size="1"> > <option value="All" selected>All</option> > <option value=0 selected>No</option> > <option value=1>Yes</option> > </select> > > The element with the O index is also selected. > > After a little investigation, I found at line 486 of Select.php > > if (is_array($this->_values) && > in_array($option['attr']['value'],$this->_values)) { > $this->_updateAttrArray($option['attr'],array('selected' => > 'selected')); > } > > The in_array() function is called, without the 3rd Parameter (strict) > > When setting this 3rd Parameter to true > if (is_array($this->_values) && > in_array($option['attr']['value'],$this->_values,1)) { > $this->_updateAttrArray($option['attr'],array('selected' => > 'selected')); > } > > The Element with the 0 index is no more selected. > > Is it a bug or I am missing something ? > > Thanks a lot for your help, and sorry for my bad English. Hi, I have looked at that and indeed, it's a bug. But the suggested patch won't do because it breaks the rest of the code. I suggest this instead: if (is_array($this->_values) && in_array((string)$option['attr']['value'], $this->_values)) { Bertrand Mansion Mamasam

« previous php.pear.dev (#19444) next »