ID: 14165 Updated by: [EMAIL PROTECTED] Reported By: steve at petabit dot com Status: Open Bug Type: Documentation problem Operating System: Linux PHP Version: 4.0.5 New Comment:
I believe the include() documentation is pretty clear on this issue: "The include() statement includes and evaluates the specified file." "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." Status -> Closed. Previous Comments: ------------------------------------------------------------------------ [2004-01-12 12:25:26] steve at petabit dot com elmicha below has answered my question perfectly well and explained the results I got too. To my mind, this docbug should be considered closed when elmicha's explanation is included in the docs for include(). Thanks to all who replied, Steve Rapaport Steve at Petabit dot com ------------------------------------------------------------------------ [2004-01-11 21:27:56] [EMAIL PROTECTED] It really doesn't imply anywhere that including a remote file will make it inherit the scope -- in fact, it says that is not the case -- and the 'include' documentation explains that the data returned will be parsed as is any included file. That is, if the page were "<?php echo '<?php $foo = \'bar\';'; ?>", the calling script would execute that assignment in its local scope. If you'd write a better explanation, I'll be happy to commit it. But since you probably don't care anymore... :-) ------------------------------------------------------------------------ [2003-08-08 11:26:50] [EMAIL PROTECTED] If you use include('http://some_server/something.php'); something.php is executed on "some_server". It's impossible to return strings with "return" from there. But the output of http://some_server/something.php is included in your script and executed there. So just make _the output_ of something.php a valid php script which sets your variables - so you can use these variables in your local script. E.g.: <?php // something.php on the remote server echo '<?php $return_value = "a string"; ?>'; ?> On the local server: <?php include('http://some_server/something.php'); echo $return_value; ?> As the manual explicitly mentions that you can use a return statement to pass values from the included script, but does not mention that this doesn't work via HTTP or FTP, I'd say this is a Documentation problem. (I don't know what the manual said in 2001, maybe the return statement could not be used in included files back then.) ------------------------------------------------------------------------ [2003-08-06 21:09:41] tim at pmedia dot be Allow me to rephrase Steve's problem described in #14165 again as I'm experiencing the same trouble. When including a remote php-file (a php-file on another server) in a script, that php-file is parsed (if server configured to) which basically means the script is runned. The problem we experience is that the parsed script's return value(s) defined at the end in a return() statement don't seem to arrive in the original script. Steve reports only 'integers'. I have seen only a '1', which is according the docs just the value returned if no return() statement is used. If the 2 scripts are located on the same server, the problem doesn't show up. ------------------------------------------------------------------------ [2001-11-21 17:32:22] steve at petabit dot com Okay, there's some simple sample code at bug 14164. Basic idea is that I have 2 machines, one public, one firewalled and non-routed. The public one should be able to access the database on the private one, but nobody else should. Thanks for the attention! Steve ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/14165 -- Edit this bug report at http://bugs.php.net/?id=14165&edit=1