For some reason this function won’t return the value ciao:
$a = "ciao";
function a() {
return $a;
}
I have no idea why.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Functions can only return variables they have in their local space, called scope:
Will return
hello, because withina(),$ais a variable of it’s own. If you need a variable within the function, pass it as parameter:BTW, if you enable NOTICES to be reported (
error_reporting(-1);), PHP would have given you notice thatreturn $ain your original code was using a undefined variable.