Jump to content

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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.