Forum Moderators: coopster

Message Too Old, No Replies

Referencing external functions from functions & classes

         

fintan

11:22 am on May 8, 2006 (gmt 0)

10+ Year Member



Hi can someone show me the proper way to call an external function from within a fuction or a class?

Would it be something like this?

$test = myfunciton($var1,$var2);

function testing($variable1, $test){

do something...

}

Thanks

fintan.

coopster

10:10 pm on May 11, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You just call it like you would normally call any other PHP function.
function squareIt($n) 
{
return $n*$n;
}
function doSomeMath($n)
{
return squareIt($n);
}
print doSomeMath(5); // prints 25

fintan

9:50 am on May 15, 2006 (gmt 0)

10+ Year Member



Thanks coopster I'd assume it's the same for classes with internal and external functions?

coopster

4:51 pm on May 15, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Did you try it?
function squareIt($n)  
{
return $n*$n;
}
class myMathClass
{
function doSomeMath($n)
{
return squareIt($n);
}
}
$math = new myMathClass();
print $math->doSomeMath(5); // prints 25
exit;

The answer is yes, it works ;)