Req #70906 [NEW]: Error on string keyed array for call_user_func_array() et. al

From: Date: Fri, 13 Nov 2015 01:44:56 +0000
Subject: Req #70906 [NEW]: Error on string keyed array for call_user_func_array() et. al
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197214@lists.php.net to get a copy of this message
From:             chris dot wisefool at gmail dot com
Operating system: 
PHP version:      Irrelevant
Package:          *General Issues
Bug Type:         Feature/Change Request
Bug description:Error on string keyed array for call_user_func_array() et. al

Description:
------------
This is more a shot in the dark than an actual expected change, as I am
sure PHP's devs are reluctant to change long-standing functionality that
doesn't issue notices so that it does.

Currently if you invoke call_user_func_array() or
ReflectionMethod::invokeArgs with an array having string keys, it
accepts the array, silently I guess calling array_values() on it. This,
however, could easily fool beginners into thinking that it can map to
the named parameters of the function (they should RTFM, but we all know
a lot won't). If an error (even NOTICE) was thrown in this case, it
would seem better. 

As an added benefit, if this was done, since calling
call_user_func_array() et. al with an associative array would be
effectively an error case, call_user_func_array could maybe later be
extended to actually supply named parameters. Since I imagine a lot of
framework code just passes to these functions, the framework users would
for free get ability to provide named parameters too. That enhancement,
however, is outside the scope of this ticket, of course. 



Test script:
---------------
function doSomething($baz=null, $bar=null) {return
compact('baz','bar')}

call_user_func_array('doSomething', array('baz'=>3,'bar'=>5)); 
// case #1 - returns array('baz'=>3,'bar'=>5)

call_user_func_array('doSomething', array('baz'=>3,'bar'=>5)); 
// case #2 - also returns array('baz'=>3,'bar'=>5)

// thus, someone could easily think that:
call_user_func_array('doSomething', array('bar'=>5,'baz'=>3));
// #case 3 - would also return array('baz'=>3,'bar'=>5)
// but it doesn't, of course, instead returning
array('baz'=>5,'bar'=>3)

// I'm proposing that in case 2 & 3 that a NOTICE is generated:
// Notice: Calling call_user_func_array() with string keys: interpreted
as
// indexed array. 
// or whatever better wording PHP dev's come up with


-- 
Edit bug report at https://bugs.php.net/bug.php?id=70906&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=70906&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=70906&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=70906&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=70906&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=70906&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=70906&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=70906&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=70906&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=70906&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=70906&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=70906&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=70906&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=70906&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70906&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=70906&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=70906&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=70906&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70906&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=70906&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=70906&r=mysqlcfg



Thread (2 messages)

« previous php.bugs (#197214) next »