Jump to content

Include within a function


x1nick

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/163553-include-within-a-function/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.