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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 13:01:30 2024 UTC