#111 bug in determining "selected" option in select

OOH Forms (8)

The following is an error found in of_select with
version string
* $Id: of_select.inc,v 1.2 2002/04/28 03:59:32
richardarcher Exp $

I am using php 4.3 on linux.

The self get function contains a bug that may be due to
php's handling of arrays/strings...

the line

if (!$this->multiple &&
($this->value==$o["value"] || $this->value==$o))

is going to print selected if this->multiple is set to
false and either $o['"value"] or $o == $this->value.

Simple enough, except that i was getting false
positives in a date select box. The current day is
"03" and both the "03" option and the "30" and "31"
options all had the "selected" option in the resulting
combo box.

A var dump or two revealed the problem. $o is a string
type, but indexing into it with "value" returned the
first char of the string. So, for example, the
following code:
$o = "30";

yields the string "3"!

I am assuming that php is evaluating "value" as an int
which would make it 0 and using this value to index
into the string...

This sort of makes sense: strings can be treated as
arrays, but only (obviously) with numeric indexes...
It seems, though, that indexing a string with a string
is likely to be a programmer error and should throw at
least a warning. (Course maybe I don't have my
reporting level turned up high enough...)

The solution is to check the type before indexing into
it.... The following code seems to resolve the problem...

if (!$this->multiple &&
(($this->value==$o["value"] && is_array($o)) ||

Simeon Franklin


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks