function foo () {
global $var;
// rest of code
}
Run Code Online (Sandbox Code Playgroud)
在我的小PHP项目中,我通常采用程序方式.我通常有一个包含系统配置的变量,当我需要在函数中访问此变量时,我会这样做global $var;.
这是不好的做法吗?
以下代码来自教程(http://net.tutsplus.com/php/creating-a-php5-framework-part-1/),而不是我的.
我对这段代码有几个疑问......
我只想弄清楚是否应该在我自己的MVC框架实现中使用这种设计模式.谢谢!
<?php
/**
* The PCARegistry object
* Implements the Registry and Singleton design patterns
* @version 0.1
* @author Michael Peacock
*/
class PCARegistry {
/**
* Our array of objects
* @access private
*/
private static $objects = array();
/**
* Our array of settings
* @access private
*/
private static $settings = array();
/**
* The frameworks human readable name
* @access private
*/
private static $frameworkName = 'PCA …Run Code Online (Sandbox Code Playgroud)