Ask a Question related to PHP Development, Design and Development.
-
Tony #1
PHP function question
When writing a function that takes in a variable number of parameters and
processing it using func_get_args or a similar technique, I'm assuming that
one is only able to use the pass by value method of parameter passing. Can
someone confirm or deny this for me?
Below is a trivial example of what I'm talking about. I'm assuming the
function below does nothing useful.
<?php
function squares( )
{
$params=function_get_args();
$numparams= func_num_args();
for ($i=0;$i<$numparams;$i++)
$params[$i]*=$params[$i];
}
?>
Tony Guest
-
IIF function question
I'm studying for my ColdFusionMX exam using Ben Forta's study guide. There is quite a bit of errata in the book, including code that simply doesn't... -
Function Question
Hi! Is there a considerable degredidation in speed if I where to include an ASP page into every other ASP page that would contain all the... -
Simple AS function question
Why will this not work home_btn.onRollOver = setInterval(delayAction,2000,home); function delayAction (framename:String) var name:String =... -
utf8_decode function question
Hi folks, I read in a security note that something known as a cross-site scripting attacker can use utf8 encoding and that you could decode data to... -
Question: ConnectToDatabase function
Thanks! I wasn't sure if the Try code would continue or not if an exception was "caught". Now I know it doesn't. "Marina" <mzlatkina@hotmail.com>... -
Pedro Graca #2
Re: PHP function question
["Followup-To:" header set to comp.lang.php.]
Tony wrote:I think you're right.> When writing a function that takes in a variable number of parameters and
> processing it using func_get_args or a similar technique, I'm assuming that
> one is only able to use the pass by value method of parameter passing. Can
> someone confirm or deny this for me?
> Below is a trivial example of what I'm talking about. I'm assuming the
> function below does nothing useful.
>
><?php
>
> function squares( )
> {
> $params=function_get_args();
> $numparams= func_num_args();
> for ($i=0;$i<$numparams;$i++)
> $params[$i]*=$params[$i];
> }
>
> ?>
But you can use the $GLOBALS variable to pretend you're passing by
reference.
Here's a way
<?php
function squares() {
$parms = func_get_args();
$nparms = func_num_args();
$retval = array(); // return array
for ($i = 0; $i < $nparms; ++$i)
if ($parms[$i]{0} == '$')
$GLOBALS[substr($parms[$i], 1)] *=
$GLOBALS[substr($parms[$i], 1)];
else $retval[] = $parms[$i] * $parms[$i];
return $retval;
}
$a = 6; $b = 7; $c = 8;
$res = squares($a, "$b", '$c');
print_r($res);
echo $c;
?>
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Pedro Graca Guest



Reply With Quote

