In requiredfile.php I define $a = 5. The in index.php I do this:
require_once(requiredfile.php);
echo $a;
But it seems that $a is not defined. Why is this?
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.
In general it is possible to access global variables the way you do.
So two possibilities come to mind to explain your issue:
you declare the variable not on global scope, but inside a class or function definition.
your
require_once()command fails (any errors in the log file?) due to the fact that you forgot the quotes around the file name or because the file is not found at that position (check the path!).