php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #50945 [PATCH] func_get_args(offset=0)
Submitted: 2010-02-06 07:53 UTC Modified: 2012-04-02 00:31 UTC
Votes:4
Avg. Score:4.0 ± 1.0
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:1 (25.0%)
From: robert at binalan dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 5.2.12 OS: FreeBSD
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: robert at binalan dot com
New email:
PHP Version: OS:

 

 [2010-02-06 07:53 UTC] robert at binalan dot com
Description:
------------
function moduleNotify($module, $message/*, ...args*/)
{
	switch($module){
	case 'Database':
		list($host, $user, $pass, $base) = func_get_args(2);
	break;
	case 'UserLogin':
		list($user, $pass, $iris, $lang) = func_get_args(2);
	break;
}
/*
feature request:
func_get_args(offset=0)
returns arguments in same zero based array from a given offset in the argument list.
*/


Patches

func-get-args-with-offset (last revision 2010-03-06 11:50 UTC by kalle@php.net)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-02-16 21:30 UTC] kwilson at shuttlebox dot net
Why wouldn't you just use array_shift? The PHP folks don't seem to like to implement features when there is already an approach to accomplish the task in few steps:

function moduleNotify($module, $message/*, ...args*/)
{
        $data = array_shift(array_shift(func_get_args()));

	switch($module){
	case 'Database':
		list($host, $user, $pass, $base) = $data;
	break;
	case 'UserLogin':
		list($user, $pass, $iris, $lang) = $data;
	break;
}
 [2010-03-06 12:50 UTC] kalle@php.net
The following patch has been added/updated:

Patch Name: func-get-args-with-offset
Revision:   1267876228
URL:        http://bugs.php.net/patch-display.php?bug=50945&patch=func-get-args-with-offset&revision=1267876228&display=1
 [2010-03-09 12:20 UTC] kalle@php.net
-Summary: func_get_args(offset=0) +Summary: [PATCH] func_get_args(offset=0)
 [2010-08-28 14:29 UTC] + at ni-po dot com
@kwilson: Maybe this is a reason why he doesn't like to use array_shift: You already used it wrong! To make it work you would need to write:

$data = func_get_args();
array_shift($data);
array_shift($data);

Better use array_slice:

$data = array_slice(func_get_args(), 2);

(This only works as of PHP 5.3, in PHP 5.2 you need to write: $data = func_get_args(); $data = array_slice($data, 2);.)

I do support the introduction of this additional parameter. It is annoying to always array_shift / array_slice some stuff from the arguments ;)
 [2010-11-24 14:10 UTC] jani@php.net
-Package: Feature/Change Request +Package: *General Issues
 [2012-03-31 03:19 UTC] phristen at yahoo dot com
Exactly, array_slice is what you wanna do.
Which is why it would probably be best to add 2 optional parameters to func_get_args, and not just one. So it will behave exactly like array_slice.
 [2012-03-31 05:32 UTC] robert at binalan dot com
I've posted this over two years ago. Nice someone still replies to it.

Changes often goes slow. I mean we have to wait till >= 5.3 so func_get_args() is finally able to be used as a function argument. Which I think is ridiculous by the way.

I still believe an offset argument is well at place in func_get args(), as part of function handling functions. I hope and wonder if this suggestion is considered by PHP.

But knowing the speed in which suggestions for enhancements will make it to the surface, it would probably take that extra beneficial planet alignment again for having that briliant moment in which the (damn) offset param is added. That alignment should be there again somewhere around PHP 8.5 in 2020... so hang in there guys! ;-)
 [2012-04-02 00:31 UTC] aharvey@php.net
-Status: Open +Status: Wont fix
 [2012-04-02 00:31 UTC] aharvey@php.net
You can do this in userspace right now with array_slice(), as has been pointed 
out. No need to complicate the implementation in PHP.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 18:01:35 2024 UTC