#31856 [NEW]: require/include fails to make variables/functions persist
| From: | ftpub at compuserve dot com | Date: | Sat, 05 Feb 2005 20:45:25 +0000 |
| Subject: | #31856 [NEW]: require/include fails to make variables/functions persist | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-73531@lists.php.net to get a copy of this message | ||
From: ftpub at compuserve dot com
Operating system: Win98 SE
PHP version: Irrelevant
PHP Bug Type: *Directory/Filesystem functions
Bug description: require/include fails to make variables/functions persist
Description:
------------
All code is in the reproduce section.
First, I create a php file with the "inc" extension
on my server root (http://localhost/www) and call it
"myinclude.inc".
Next, I create a regular php file (in the same location)
and call it "myscript.php".
I run myscript.php from my browser and I get the following:
------------------------------
in the include
YAY!
------------------------------
It works.
NOW: THE PROBLEM
I rename "myinclude.inc" to "myinclude.php".
I change line 2 of "myscript.php" accordingly.
I again run "myscript.php" from my browser and I get the
following:
----------------------
in the include
NAY!
----------------------
Obviously, require() and include() do not make the
"myvar" variable persist. Also, when I declare functions in
an included file which HAS THE "PHP" EXTENSION, the
function cannot be called. However, as shown above, if I
use the "INC" or any other extension, everything works.
ANOTHER ODDITY
Since the two files "myinclude.php" and "myscript.php"
are both in the same directory I tried not using the
"http://localhost/www" part in line 2 of
"myscript.php".
IT WORKS. Why?
Please advise.
Thank you.
Other Information:
PHP Version = 4.3.2
Apache Version = 2.0.46
Reproduce code:
---------------
---myinclude.inc--------------
1: <?php
2: $myvar = 2;
3: print "in the include\n";
4: ?>
------------------------------
---myscript.php---------------
1: <?php
2: require("http://localhost/www/myinclude.inc");
3: if ($myvar == 2) print "YAY!";
4: else print "NAY!";
5: ?>
------------------------------
Expected result:
----------------
PLEASE SEE DESCRIPTION
---------
in the include
YAY!
---------
if i rename "myinclude.inc" to "myinclude.php"
and change "myscript.php" accordingly:
---------
in the include
NAY!
---------
Actual result:
--------------
PLEASE SEE DESCRIPTION
--
Edit bug report at http://bugs.php.net/?id=31856&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31856&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=31856&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=31856&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=31856&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=31856&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=31856&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=31856&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=31856&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=31856&r=support
Expected behavior: http://bugs.php.net/fix.php?id=31856&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=31856&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=31856&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=31856&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31856&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=31856&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=31856&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=31856&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=31856&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=31856&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=31856&r=mysqlcfg