php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #64056 array_rand returns differ - should always be an array
Submitted: 2013-01-23 14:57 UTC Modified: 2013-01-23 15:06 UTC
From: joern dot berkefeld at bittubes dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: Irrelevant OS: -
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: joern dot berkefeld at bittubes dot com
New email:
PHP Version: OS:

 

 [2013-01-23 14:57 UTC] joern dot berkefeld at bittubes dot com
Description:
------------
---
From manual page: http://www.php.net/function.array-rand
---

From the manual:
"If you are picking only one entry, array_rand() returns the key for a random 
entry. Otherwise, it returns an array of keys for the random entries"

That causes problems as this functionality is unexpected. Functions should always 
return the same type (or false / null for failure)

Expected result:
----------------
get an array regardless of the number of results

Actual result:
--------------
the function returns an integer for one result and an array for multiple results

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-23 15:06 UTC] pajoye@php.net
We can't change that due to backward compatibility reason.
 [2013-01-23 15:06 UTC] pajoye@php.net
-Status: Open +Status: Wont fix
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 20:01:36 2025 UTC