Page 1 of 1
Return
Posted: Sat Oct 14, 2006 12:02 pm
by impulse()
Could somebody point out why this code returns the following errors:
Missing argument 1 for One()
Missing argument 1 for Two()
Undefined variable: var
Code: Select all
function One($var) {
$var = 10;
return $var;
}
function Two($var) {
echo $var;
return $var;
}
Two();
Stephen,
Posted: Sat Oct 14, 2006 12:08 pm
by feyd
The variables in the parentheses following the function name are arguments/parameters for the function. You've defined two functions that require an argument when called.
Your code doesn't even call One().
Posted: Sat Oct 14, 2006 12:20 pm
by Cameri
If what you are trying to do is give the variables default values, you should do it like this:
Code: Select all
function One($var=10) {
return $var;
}
function Two($var="") {
echo $var;
return $var;
}
One(); // 10
Two(); // useless
One(20); // 20
Two("Test"); // Test
Posted: Sat Oct 14, 2006 12:41 pm
by impulse()
I'm trying to access a variable from function A inside of function B.
Posted: Sat Oct 14, 2006 1:02 pm
by John Cartwright
Code: Select all
function One($var=10) {
return $var;
}
function Two($var) {
echo $var;
return $var;
}
$one = One();
$two = Two($one);
Posted: Sat Oct 14, 2006 1:59 pm
by RobertGonzalez
Jcart wrote:Code: Select all
function One($var=10) {
return $var;
}
function Two($var) {
echo $var;
return $var;
}
$one = One();
$two = Two($one);
Test it be using: