php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34120 func_get_arg() can be used function call parameter if used only once
Submitted: 2005-08-13 13:58 UTC Modified: 2005-10-21 10:11 UTC
Votes:4
Avg. Score:3.8 ± 1.3
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: ondrej at sury dot org Assigned: dmitry (profile)
Status: Wont fix Package: Scripting Engine problem
PHP Version: 5CVS, 4CVS (2005-08-013) OS: *
Private report: No CVE-ID: None
 [2005-08-13 13:58 UTC] ondrej at sury dot org
Description:
------------
func_get_arg() can be used as argument to function only once.

Reproduce code:
---------------
<?php

function doTitle($a = NULL, $b = NULL) {
  print "doTitle: $a, $b\n";
}

function doHead() {
  doTitle(func_get_arg(0));
  doTitle(func_get_arg(1));
  doTitle(func_get_arg(0), "3");
  doTitle(func_get_arg(0), func_get_arg(1));
}

doHead("1", "2");

?>


Expected result:
----------------
doTitle: 1,
doTitle: 2,
doTitle: 1, 3
doTitle: 1, 2


Actual result:
--------------
doTitle: 1,
doTitle: 2,
doTitle: 1, 3

Fatal error: func_get_arg(): Can't be used as a function parameter in /tmp/func_get_arg.php on line 11


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-13 14:37 UTC] ondrej at sury dot org
Hi Derrick,

I don't consider to be bug, that it cannot be used as function argument.

However I consider to be bug, that it CAN be used if you use it only once.

This works:

doTitle(func_get_arg(0));

This works also:
doTitle(func_get_arg(1));

So it should not work at all, to be consistent.

Ondrej.
 [2005-08-13 14:38 UTC] derick@php.net
Well, that's true then. But I'm not sure how important this bug is :)
 [2005-08-13 20:23 UTC] sniper@php.net
Manual says:

"Note: Because this function depends on the current scope to determine parameter details, it cannot be used as a function parameter. If you must pass this value, assign the results to a variable, and pass the variable."

 [2005-08-15 23:08 UTC] sniper@php.net
Dmitry, this script should fail for all of those:

<?php

function doTitle($a = NULL, $b = NULL) {
  print "doTitle: $a, $b\n";
}

function doHead() {
  doTitle(func_num_args());
  doTitle(func_get_arg(0));
  doTitle(func_get_args());
}

doHead("1", "2");

 [2005-08-25 21:54 UTC] csaba at alum dot mit dot edu
Note: Because this function depends on the current scope to determine parameter details, it may only appear in the first argument to a function.  Thus

myfunc1 (myfunc2 (func_get_arg(1), 7))         OK
myfunc1 (myfunc2 (7, func_get_arg(0)))         Error
myfunc1 (7+func_get_arg(0)+func_get_arg(1))    OK
myfunc2 (func_get_arg(0), func_get_arg(1))     Error

If you must pass this value of func_get_arg() not in the first argument, assign the results to a variable, and pass the variable."

Csaba Gabor from Vienna
 [2005-09-01 15:55 UTC] dmitry@php.net
Right.
I think this shouldn't be fixed.
 [2005-09-01 16:32 UTC] ondrej at sury dot org
I disagree, this function should fail even when used as first argument (also according to docs).

If you allow it to be passed as first argument, but not as second or third, etc., you create only chaos.

It's much more cleaner to let it fail everytime.
 [2005-10-21 10:11 UTC] dmitry@php.net
Your oppinion makes sense. But I don't see a way to implement this. It is possible to allow use it as any argument or disallow as first argument near the same cost.
I prefer first decision but not for 4.*, 5.*.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 14:01:29 2024 UTC