php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52551 range() warns if step exceeds the distance between the min and max values
Submitted: 2010-08-06 08:22 UTC Modified: 2013-10-05 07:49 UTC
Votes:24
Avg. Score:3.7 ± 1.1
Reproduced:22 of 23 (95.7%)
Same Version:3 (13.6%)
Same OS:0 (0.0%)
From: planet36 at gmail dot com Assigned: krakjoe (profile)
Status: Closed Package: Documentation problem
PHP Version: trunk-SVN-2010-08-06 (snap) OS: Linux
Private report: No CVE-ID: None
 [2010-08-06 08:22 UTC] planet36 at gmail dot com
Description:
------------
The range() function incorrectly warns when the step size exceeds the distance between the min and the max values.  But when the min and max values are equal, there is no warning.  This is related to #21060 and #46631.

The documentation at <http://www.php.net/manual/en/function.range.php> gives no mention of possible warnings or errors.

The 'seq' utility is a good guide as to the expected output of the test script.
$ seq 1 2 4
1
3

$ seq 1 2 3
1
3

$ seq 1 2 2
1

$ seq 1 2 1
1


Test script:
---------------
print "range(1, 4, 2)\n";
print_r(range(1, 4, 2));
print "\n";

print "range(1, 3, 2)\n";
print_r(range(1, 3, 2));
print "\n";

print "range(1, 2, 2)\n";
print_r(range(1, 2, 2));
print "\n";

print "range(1, 1, 2)\n";
print_r(range(1, 1, 2));
print "\n";

Expected result:
----------------
range(1, 4, 2)
Array
(
    [0] => 1
    [1] => 3
)

range(1, 3, 2)
Array
(
    [0] => 1
    [1] => 3
)

range(1, 2, 2)
Array
(
    [0] => 1
)

range(1, 1, 2)
Array
(
    [0] => 1
)

Actual result:
--------------
range(1, 4, 2)
Array
(
    [0] => 1
    [1] => 3
)

range(1, 3, 2)
Array
(
    [0] => 1
    [1] => 3
)

range(1, 2, 2)

Warning: range(): step exceeds the specified range in /home/stevew/Desktop/PHP/php-trunk-201008060430/sapi/cli/test-range.php on line 16

range(1, 1, 2)
Array
(
    [0] => 1
)

Patches

array.c.diff (last revision 2010-08-06 06:38 UTC by planet36 at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-06 08:24 UTC] planet36 at gmail dot com
uname --all
Linux ubuntu 2.6.32-24-generic-pae #38-Ubuntu SMP Mon Jul 5 10:54:21 UTC 2010 i686 GNU/Linux

./php --version
PHP 5.3.99-dev (cli) (built: Aug  6 2010 01:43:07) 
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2010 Zend Technologies
 [2011-11-16 14:10 UTC] felipe@php.net
-Package: *General Issues +Package: Documentation problem
 [2013-10-05 07:49 UTC] krakjoe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: krakjoe
 [2013-10-05 07:49 UTC] krakjoe@php.net
There is no convention or necessity to document every warning or error that a function may produce.

I don't see a reason for this bug to remain open.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 21:01:36 2024 UTC