Edit report at https://bugs.php.net/bug.php?id=62431&edit=1

 ID:                 62431
 Updated by:         ni...@php.net
 Reported by:        gmblar+php at gmail dot com
 Summary:            array_fill_keys must always return an array
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Arrays related
 Operating System:   Linux
 PHP Version:        5.4.4
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2012-06-27 16:06:06] 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



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=62431&edit=1

Reply via email to