x1nick Posted June 24, 2009 Share Posted June 24, 2009 Writing a small CMS and I have wrote a function which includes another PHP file. The reason for this: if the file does not exist, then I want a custom error Seems to work besides one thing. Once the file is included, I can't access the variables set within the included file. What have I missed here? Its been a long day and just can't work out why this wont work. Quote Link to comment https://forums.phpfreaks.com/topic/163553-include-within-a-function/ Share on other sites More sharing options...
Alex Posted June 24, 2009 Share Posted June 24, 2009 Edit: Whoops, my mistake... Read the manual: http://us3.php.net/manual/en/function.include.php When a file is included, the code it contains inherits the variable scope of the line on which the include occurs. Any variables available at that line in the calling file will be available within the called file, from that point forward. However, all functions and classes defined in the included file have the global scope. Quote Link to comment https://forums.phpfreaks.com/topic/163553-include-within-a-function/#findComment-862886 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.