hatrickpatrick Posted January 26, 2008 Share Posted January 26, 2008 I have a weird problem with a script I'm writing: If I have a file, file1.php, and a second file, file2.php: file1.php contains this: <? $text="The Text String"; ?> file2.php is this: <? include("file1.php"); echo $text; ?> file2.php will output "The Text String". However, the following scripts will NOT output anything: file1.php: <? $text="The Text String"; include("file2.php"); ?> file2.php: <? echo $text; ?> Why is this? It seems that after you've included a file, the parent file can call variables from the included file, but an included file cannot use variables declared in the parent? Hve I misconfigured php.ini or something? Quote Link to comment https://forums.phpfreaks.com/topic/87906-weird-problem-included-files-do-not-register-variables-declared-in-the-parent/ Share on other sites More sharing options...
Aureole Posted January 26, 2008 Share Posted January 26, 2008 Must be a misconfiguration because that doesn't happen to me. Quote Link to comment https://forums.phpfreaks.com/topic/87906-weird-problem-included-files-do-not-register-variables-declared-in-the-parent/#findComment-449761 Share on other sites More sharing options...
hatrickpatrick Posted January 26, 2008 Author Share Posted January 26, 2008 Ah - any idea which option I can change to enable it? Quote Link to comment https://forums.phpfreaks.com/topic/87906-weird-problem-included-files-do-not-register-variables-declared-in-the-parent/#findComment-449771 Share on other sites More sharing options...
PFMaBiSmAd Posted January 26, 2008 Share Posted January 26, 2008 The code you posted works. There is no setting that changes how parent/child included code works. It is unlikely that the posted code is your actual code. Your actual code either has a syntax error that is preventing it from running, an incorrect file name in the include statement, or some other problem or error that is preventing it from working. To get the quickest solution to what your code is doing, you need to post the actual code that is generating the symptoms you are seeing. Quote Link to comment https://forums.phpfreaks.com/topic/87906-weird-problem-included-files-do-not-register-variables-declared-in-the-parent/#findComment-449779 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.