On 2 August 2011 13:45, Sharl.Jimh.Tsin <amoiz.shine@xxxxxxxxx> wrote: > 在 2011-08-02二的 13:33 +0100,Richard Quadling写道: > >> It is to do with variable scope. >> >> http://uk.php.net/manual/en/language.variables.scope.php / >> http://uk.php.net/manual/zh/language.variables.scope.php >> > > Thanks for your useful URL.According to the doc,i must make the var > global by using "$GLOBALS" so that access it in the same page/context. > > just a bit unbelievable...HAHA. For many many languages, scope is essential. PHP has had scope since day 1 (OK, I'm pretty sure PHP has had scope since day 1). It is also considered poor design to have all your variables in the global scope. It means that you have to remember every single variable name you've ever used in every include file so that you don't conflict with one if it is currently in use. It also means that all data is always available all the time. For many developers, this would be a serious issue. If you are happy to live with these constraints, then you are certainly able to put all your variables in the global scope and PHP will quite happily help you by the use of $GLOBALS and global. But you will find yourself doing a LOT of additional work as you will have to type $GLOBAL['var'] for every single variable outside of a function or method, or you will have to declare the variables as global inside every function and method or you will have to pass the variables to the function or method as a parameter. -- Richard Quadling Twitter : EE : Zend : PHPDoc @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php