Re: include file to global scope

From: Date: Wed, 12 Oct 2005 11:04:44 +0000
Subject: Re: include file to global scope
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-223955@lists.php.net to get a copy of this message
> first off I would recommend that you 'pollute' your global scope as > little as possible. I agree at all! Thats my opinion, and i don't use global variables at all. The problem is, other people do. And if I need to use their code I must include it. > that said the solution will probably involve the use of the 'global' > keyword. Yes, see example files 1 and 2. This files are very simple, but shows the problem. Naturly the decision what file to include an when is complexer than that. The file2.php represents a large standalone "old" php file. Doesn't maintend by me. It works fine. The file1.php5 represents a newer application. File2 will not work, because $abc is not a global var. Ok, I could search for all declared vars and add a global to it. Thats not realy a "nice" solution. Do anyone have a better Idea? Claudio file1.php5: ----- <?php class testInc { public static function incFile($x) { return include_once($x); } } testInc::incFile('file2.php'); ?> ----- file2.php: ----- <?php $abc = true; function anotherOne() { global $abc; if ($abc) { echo 'it works'; } else { echo 'failure'; } } anotherOne(); ?> -----

« previous php.general (#223955) next »