|
Posted by "Claudio" on 10/12/05 14:04
> 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();
?>
-----
Navigation:
[Reply to this message]
|