While it would work, it is an inelegant method because the inner-workings of the function must be dug into, and the calling file must be modified to work with the function in the future. The best method is to be able to call the function using any variable name the author wants to send as a parameter. That way, you can just drop the function into any script and call it without having to re-write any variables or function inner-workings.hallsofvallhalla wrote:ah i see what your saying..i had a real dumb moment
Noc might better answer this due to I dont use functions in PHP very often and when I do passing them works for me but I also haven't gotten into the require file that much. I use Javascript for my functions. But off the top of my head I can think of a alternative.
Make a variable
lets say $dthis
then in your function
display_this()
{
echo $dthis;
}
now before you pass any variable to it simply define $dthis
example:
$a = 10;
$b = 10;
$dthis = $a;
display_this();
$dthis = $b;
display_this();
that will print out
10
20
hope that helps and you have raised a question I must research for I am curious now too.
edit: or actually it will print out 1020 becasue I didnt break the line
Or at least, that is the best method to me, being a child of OOP.