php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66793 range(0,9) and range('0','9') both produce intergers in array
Submitted: 2014-02-27 23:52 UTC Modified: 2014-02-28 10:33 UTC
From: araustin at gmail dot com Assigned:
Status: Not a bug Package: Output Control
PHP Version: 5.4.25 OS: Win 8
Private report: No CVE-ID: None
 [2014-02-27 23:52 UTC] araustin at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.range
---


Test script:
---------------
$allowedChars_num = range(0,9);
$allowedChars_str = range('0','9');
var_dump($allowedChars_num);
var_dump($allowedChars_str);

Expected result:
----------------
range(0,9) is proper, making an array of integers
range('0','9') should be making an array of strings, ex: '0','1','2' etc...

Actual result:
--------------
array(10) { [0]=> int(0) [1]=> int(1) [2]=> int(2) [3]=> int(3) [4]=> int(4) [5]=> int(5) [6]=> int(6) [7]=> int(7) [8]=> int(8) [9]=> int(9) } 

array(10) { [0]=> int(0) [1]=> int(1) [2]=> int(2) [3]=> int(3) [4]=> int(4) [5]=> int(5) [6]=> int(6) [7]=> int(7) [8]=> int(8) [9]=> int(9) } 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-02-28 10:33 UTC] ab@php.net
-Status: Open +Status: Wont fix
 [2014-02-28 10:33 UTC] ab@php.net
That may sound logic for your particular example, however if you spread it with say range('24','42'), it'll become inconsistent. Concatenation with integer still works, and the way it's handled now is consistent - numeric strings become numbers, it was introduced somewhere in PHP-4 according to the doc page. And btw that is platform independent behavior.
 [2014-02-28 10:33 UTC] ab@php.net
-Status: Wont fix +Status: Not a bug
 [2014-02-28 21:10 UTC] a dot r dot austin at gmail dot com
You say that what about range('24','42') ??? Well, it is the same as to ask what about range('pk','rt')... It does not make sense. If is it a string, it should be an ascii character, one char long. 

range('24','42') should be error of some sorts just like range('pk','rt')
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Nov 30 04:05:54 2022 UTC