Bug #72784 [NEW]: BC break in rand(): throws warning in 7.1 and returns FALSE for max-min range
From: bugs dot php dot net at majkl578 dot cz
Operating system:
PHP version: 7.1.0beta2
Package: Math related
Bug Type: Bug
Bug description:BC break in rand(): throws warning in 7.1 and returns FALSE for max-min range
Description:
------------
When rand() is given parameters in the reverse order - max first, min
second, it now throws warning and returns FALSE. In all previous PHP
versions it did not return any warning and returned the a number from
the range.
This is especially tricky in scripts where rand() is supplied arguments
from variable, it'd be now required to write rand(min($a, $b), max($a,
$b)) instead of just rand($a, $b).
Although I understand the reasoning behind requiring specific order,
returning FALSE is a BC break and should not be introduced in 7.x
(warning is IMHO fine though).
Test script:
---------------
var_dump(rand(5, 1));
Expected result:
----------------
int(N)
Actual result:
--------------
Warning: rand(): max(1) is smaller than min(5) ...
bool(false)
--
Edit bug report at https://bugs.php.net/bug.php?id=72784&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72784&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72784&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72784&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72784&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72784&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72784&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72784&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72784&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72784&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72784&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72784&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72784&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72784&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72784&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72784&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72784&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72784&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72784&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72784&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72784&r=mysqlcfg
Thread (7 messages)
- bugs dot php dot net at majkl578 dot cz