php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62431 array_fill_keys must always return an array
Submitted: 2012-06-27 16:06 UTC Modified: 2012-06-27 18:05 UTC
From: gmblar+php at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.4.4 OS: Linux
Private report: No CVE-ID: None
 [2012-06-27 16:06 UTC] gmblar+php at gmail dot com
Description:
------------
array_fill_keys must always return an array as described in 
http://de3.php.net/manual/en/function.array-fill-keys.php.

When call array_fill_keys with invalid arguments the function returns an invalid 
null!

Test script:
---------------
<?php

var_dump(array_fill_keys(array('a', 'b', 'c')));
var_dump(array_fill_keys(true, 1));
var_dump(array_fill_keys('', 2));
var_dump(array_fill_keys(NULL, 3));
var_dump(array_fill_keys());



Expected result:
----------------
Warning: array_fill_keys() expects parameter 1 to be array, boolean given in - on 
line 4
array(0) {
}

Warning: array_fill_keys() expects parameter 1 to be array, string given in - on 
line 5
array(0) {
}

Warning: array_fill_keys() expects parameter 1 to be array, null given in - on 
line 6
array(0) {
}

Warning: array_fill_keys() expects exactly 2 parameters, 0 given in - on line 7
array(0) {
}


Actual result:
--------------
Warning: array_fill_keys() expects exactly 2 parameters, 1 given in - on line 3
NULL

Warning: array_fill_keys() expects parameter 1 to be array, boolean given in - on 
line 4
NULL

Warning: array_fill_keys() expects parameter 1 to be array, string given in - on 
line 5
NULL

Warning: array_fill_keys() expects parameter 1 to be array, null given in - on 
line 6
NULL

Warning: array_fill_keys() expects exactly 2 parameters, 0 given in - on line 7
NULL


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-06-27 18:05 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2012-06-27 18:05 UTC] nikic@php.net
All PHP functions return NULL when called with incorrect parameters. This is nothing special about array_fill_keys(). As this is the same for all functions it is not specially mentioned on every single function docs page.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 13:01:30 2024 UTC