|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-08-07 20:13 UTC] 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. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 25 03:00:01 2025 UTC |
It has nothing to do with include but just the scope, your scripts are just the same as this: <?php function testfunction() { global $anObject, $aVariable; // this makes it work function somefunction() { global $anObject, $aVariable; print $anObject->somefunction(); print $aVariable; } class AnotherClass { function somefunction() { return "hello\n"; } } $anObject = new AnotherClass(); $aVariable = "a string"; somefunction(); } testfunction(); ?>