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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
50 - 10 = ?
Subscribe to this entry?

 
 [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: Sat May 18 20:01:34 2024 UTC