Ask a Question related to PHP Development, Design and Development.
-
DutchFish #1
How to get parameter names from defined function
Dear develoopers,
I know i can reveal the defined functions with:
<?php
function myrow($id, $data) {
return "<tr><th>$id</th><td>$data</td></tr>\n";
}
$arr = get_defined_functions();
print_r($arr);
?>
But consider the next function:
<?php
function myfunction($para1, $para2, $para3) {
..
//do something with the paramaters
..
}
?>
How can I get the parameter names i.e. $para1, $para2, $para3?
Any help would be highly apreciated.
Kind regards,
DutchFish
DutchFish Guest
-
#39161 [NEW]: parameter names not sent to prepared statement
From: aspen dot olmsted at alliance dot biz Operating system: windows xp sp 2 PHP version: 5CVS-2006-10-15 (snap) PHP Bug Type: ... -
#38951 [Opn->Bgs]: ftp_ssl_connect() function not defined
ID: 38951 Updated by: derick@php.net Reported By: vinnie0921 at hotmail dot com -Status: Open +Status: ... -
User defined function causes empty result set
I have created a UDF that takes an INTEGER as parameter and returns a VARCHAR. Whenever I try to use the function in a SELECT, it causes the SELECT... -
note 33974 added to function.defined
btw: (PHP 4.1.2 + 4.3.2) echo gettype(defined('SOMETHING')); integer ---- Manual Page -- http://www.php.net/manual/en/function.defined.php... -
note 33633 added to function.defined
Pour la traduction francaise, ne pas lire ``defined -- (PHP 3, PHP 4 ) defined -- Vérifie l'existence d'une fonction Description bool defined... -
Janwillem Borleffs #2
Re: How to get parameter names from defined function
"DutchFish" <salesvast@home.nl> schreef in bericht
news:bsjnfn$ut1$1@news2.tilbu1.nb.home.nl...You can't, because they aren't important. The passed values are, and they>
> How can I get the parameter names i.e. $para1, $para2, $para3?
>
can be retrieved by using func_get_args:
[url]http://www.php.net/manual/en/function.func-get-args.php[/url]
JW
Janwillem Borleffs Guest
-
CountScubula #3
Re: How to get parameter names from defined function
"DutchFish" <salesvast@home.nl> wrote in message
news:bsjnfn$ut1$1@news2.tilbu1.nb.home.nl...First, is your question, what is the name of the variables that were passed> Dear develoopers,
>
> But consider the next function:
> <?php
> function myfunction($para1, $para2, $para3) {
> //do something with the paramaters
> }
> ?>
>
> How can I get the parameter names i.e. $para1, $para2, $para3?
> Any help would be highly apreciated.
> Kind regards,
> DutchFish
to the function?
if so here you go, a little wierd, but I do it like this, (untill i can find
something better)
$myvar = "John Doe";
$othervar = "Jane";
someFunction($myvar,$othervar);
function someFunction($para1,$para2)
{
$v1 = array_search ($para1,$GLOBALS);
print "para1 came from var: $v1 \n";
$v2 = array_search ($para2,$GLOBALS);
print "para2 came from var: $v2 \n";
}
----- this is what it spits out
para1 came from var: myvar
para2 came from var: othervar
Mike Bradley
[url]http://gzen.myhq.info[/url] -- free online php tools
CountScubula Guest
-
DJP #4
Re: How to get parameter names from defined function
you can do it like this:
<?php
function myfunction($para1, $para2, $para3) {
foreach (get_defined_vars() as $name=>$value)
{
echo $name;
}
}
?>DJP Guest
-
Unregistered #5
How to get parameter names from defined function
You can't, because they aren't important. The passed values are, and they
can be retrieved by using func_get_args:
You can, and variable names can be important as they act as keys in the KVP structure of the language. See response #4 for the right answer.Unregistered Guest
-
Unregistered #6
Re: How to get parameter names from defined function
'important' is a judgement call, no one cares what you think if you're not helping to answer the question.
Here's how:
$reflector = new ReflectionFunction('test');
$params = array();
foreach ($reflector->getParameters() as $param) {
$params[] = $param->name;
}
print_r($params);
http://stackoverflow.com/questions/3515406/how-to-determine-user-defined-function-parameters-names-before-calling-itUnregistered Guest



Reply With Quote

