php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78093 mt_rand returns NULL in some cases
Submitted: 2019-05-31 14:47 UTC Modified: 2019-05-31 14:51 UTC
From: sidorovmarat1995 at gmail dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 7.2.19 OS: All
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: sidorovmarat1995 at gmail dot com
New email:
PHP Version: OS:

 

 [2019-05-31 14:47 UTC] sidorovmarat1995 at gmail dot com
Description:
------------
In mt_rand docs I can't find possibility of returning NULL.
I suggest return false in this situation(see test script).

Test script:
---------------
<?php
var_dump(mt_rand(INF,INF));
var_dump(mt_rand(INF,NULL));

Expected result:
----------------
bool(false)
bool(false)

Actual result:
--------------
NULL
NULL

Patches

mt-rand (last revision 2019-05-31 14:48 UTC by sidorovmarat1995 at gmail dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-05-31 14:48 UTC] sidorovmarat1995 at gmail dot com
The following patch has been added/updated:

Patch Name: mt-rand
Revision:   1559314100
URL:        https://bugs.php.net/patch-display.php?bug=78093&patch=mt-rand&revision=1559314100
 [2019-05-31 14:50 UTC] sidorovmarat1995 at gmail dot com
Sorry, I don't know how to fix this issue.
And you can see my path is only random txt file from my PC.
 [2019-05-31 14:51 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2019-05-31 14:51 UTC] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

https://3v4l.org/TviI3 See the warnings?

https://www.php.net/manual/en/functions.internal.php
> Note: If the parameters given to a function are not what it expects, such as passing an array where a string is
> expected, the return value of the function is undefined. In this case it will likely return NULL but this is just
> a convention, and cannot be relied upon.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 02 20:01:32 2024 UTC