function.html_select_date.php bug?

[email protected] (Yuri Weseman)
Newsgroups php.smarty.dev
Message-ID <[email protected]>
Hi,

http://cvs.php.net/co.php/smarty/libs/plugins/function.html_select_date.php?r=1.29#201

I think there's a bug in this line. It now reads:
'selected'   => $a=$time[1] ? strftime($month_value_format, mktime(0,
0, 0, (int)$time[1], 1, 2000)) : '',

I think this would be better:

'selected'   => $time[1]>0 ? strftime($month_value_format, mktime(0,
0, 0, (int)$time[1], 1, 2000)) : '',

I don't understand why $a should be assigned as it is isn't used later
on in the code. And because $time[1] doesn't always have to be 0 (as
is the case when your date comes out of the database like 0000-00-00)
this results in december to be selected.
To explain this: The value of $time[1] is 00 then, which results in
true for the check $a=$time[1], which results in
strftime($month_value_format, mktime(0, 0, 0, (int)$time[1], 1, 2000))
being executed. And because mktime sees (int)$time[1] as 0, it thinks
it should selected the last month of the previous year resulting in
december to be selected.
You could also use (int) $time[1] instead of $time[1] > 0

Greetings,

Yuri
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.