Reply to Re: [PHP] include file to global scope

Your name:

Reply:


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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация