Re: include file to global scope

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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();
?>
-----

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux