range() error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fird01
Forum Newbie
Posts: 19
Joined: Mon Apr 07, 2008 11:04 pm

range() error

Post by fird01 »

Code: Select all

range(2010,2012);
ErrorException range() step exceeds the specified range
been searching and i cant find a solution for this..
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: range() error

Post by McInfo »

The range() function does not throw exceptions, so the message must come from a different part of your code.
fird01
Forum Newbie
Posts: 19
Joined: Mon Apr 07, 2008 11:04 pm

Re: range() error

Post by fird01 »

McInfo wrote:The range() function does not throw exceptions, so the message must come from a different part of your code.
nope.. it is from the range function..


ErrorException [ Warning ]: range() [function.range]: step exceeds the specified range
FCPATH/application\helpers\myform_helper.php [ 27 ]

Code: Select all

22         $selected = is_null($selected) ? date('Y') : $selected;
23 
24 		/*** create the select ***/
25 		$select = '<select name="'.$id.'" id="'.$id.'">';
26 		//for( $year=$start_year;$year<=$end_year;$year++ )
27 		foreach(range($start_year,$end_year) as $year)
28 		{
29 			$select .= "<option value=\"$year\"";
30 			$select .= ($year==$selected) ? ' selected="selected"' : '';
31 			$select .= ">$year</option>\n";
32 		}
{PHP internal call} » MY_Exceptions::error_handler(arguments)

start_year = 2010
end_year =2012

my exception class says otherwise.. i've been searching .. but cant solve it..
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: range() error

Post by McInfo »

What version of PHP are you running?

Put var_dump($start_year, $end_year); just before the loop. What data types are those variables?

Try explicitly setting range()'s $step parameter to 1.0. I don't really expect that to do anything, but it's worth trying.

If you make a copy and strip out code, what is the shortest script that will continue to cause the error?
Post Reply