php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31856 require/include fails to make variables/functions persist
Submitted: 2005-02-05 21:45 UTC Modified: 2005-02-05 23:45 UTC
From: ftpub at compuserve dot com Assigned:
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: Irrelevant OS: Win98 SE
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ftpub at compuserve dot com
New email:
PHP Version: OS:

 

 [2005-02-05 21:45 UTC] ftpub at compuserve dot com
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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-05 23:45 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

. 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 04 02:01:27 2024 UTC