Re: Can i take the variable name in a function?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, October 11, 2006 12:19 pm, Eric Butera wrote:
> On 10/11/06, Andy Hultgren <wearhdphp@xxxxxxxxx> wrote:
>>   <?php
>> function add_some_extra(&$string)
>> {
>>    $string .= 'and something extra.';
>> }
>> $str = 'This is a string, ';
>> add_some_extra($str);
>> echo $str;    // outputs 'This is a string, and something extra.'
>> ?>
>> I think that does what you want?
>
> In the add_some_extra example you gave he wants the named value of the
> passed parameter which is $str.

Maybe.

Or maybe he wants 'string' which is the local variable name.

Or, given the way software projects go, maybe he wanted the name of
the variable from 5 function stack-calls back...

Which is why I said it's generally not all that useful, since any
given "variable" takes on a variety of names as it gets passed around
in a web application.

Obviously a well-structured application will keep the name consistent
within a single API layer or class or module or script or whatever
unit of code it makes sense to be consistent.

But, still, sooner or later, either in the script or the guts of PHP,
al your string variables end up being named 'string' which is just not
that useful to report, when you get right down to it...  Since maybe
it's really $password or maybe it's really $username or maybe it's
$comment in the main script.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux