ID:               29562
 Comment by:       mxou at mycosmos dot gr
 Reported By:      darcy at 1000camels dot com
 Status:           Open
 Bug Type:         Scripting Engine problem
 Operating System: Linux, MacOSX
 PHP Version:      4.3.8
 New Comment:

I've also encountered the same bug and was searching if someone had
encountered it so far. Not only my own global variables are of no
scope, PHP's superglobal structures become out of scope, also.

Very irritating.


Previous Comments:
------------------------------------------------------------------------

[2004-08-11 06:22:07] darcy at 1000camels dot com

does anyone have any more information on this?  i'm finding it quite
difficult to work around this problem.  i've tried making an absolute
call with the include (ie. using http://), but that's just causing more
trouble.  i can't get access to the cookies from within an absolute
call...  And the fix i described above doesn't really help, since i'm
trying to source a rather large piece of code (phpBB2), which has lots
of globals.  too many to keep track of.  besides, i don't think it's
the best approach...

------------------------------------------------------------------------

[2004-08-10 09:57:30] cstdenis at on-track dot ca

Looks like this is happening with PHP5 (release) too.

------------------------------------------------------------------------

[2004-08-09 19:05:59] darcy at 1000camels dot com

i did some more experiments and have found a kind of fix.  It would
appear that if i globalize any of the variables which are losing scope
inside of the function which sources the code, the variables keeps
scope.  this is interesting and may help me do what i need to do, but i
still think this is a problem.

if you want to see an example of my fix, look for the files called
-fixed on my server: http://1000camels.com/phpBug/

------------------------------------------------------------------------

[2004-08-09 10:46:55] boris at hident dot co dot il

Happens to me too.
4.3.6 and 4.3.7 was fine.
4.3.8 and the 4.3.9-dev snapshots have the bug.
Tried it both in Linux (Red-Hat and Fedora Core 2) and on Windows XP
(Apache/1.3.31 (Win32)).

I export some cookie variable to global scope
$somevar = $_COOKIE['somevar'];
in an included file. The $somevar variable is always empty inside
included files from other fucntions, even though they are defined as
global. register_globals is off.

Hope this will get fixed ASAP, because restructuring my whole php
application is not an option now.

------------------------------------------------------------------------

[2004-08-07 20:13:16] darcy at 1000camels dot com

Description:
------------
This is a somewhat complicated bug to demonstrate.  i have placed files
online so that the behaviour can be demonstrated.

Essentially, the bug is that when you include a php script using
include() with a relative url (not absolute), global variables used
within a function in the sourced code are not available.

this seems to occur only when the original include() is within a class
or function.  if it is in open code, it works find.

it's a complex bug and i'm not sure the best way to analyze.

Reproduce code:
---------------
http://1000camels.com/phpBug/

four files (and their source):

test-open-code.php - works
test-within-class.php - does not work
test-within-function.php - does not work

testMod.php - code which is being sourced

Expected result:
----------------
i expect the global variable to be available

Actual result:
--------------
the global variable (in my example $anObject and $aVariable) are not
available.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=29562&edit=1

Reply via email to