我必须从其他几个类中访问一个类。我想知道是否更好地使用全球'或者将课程传授给其他班级。
$m_class = new SOmeClass();
#1 -
class AnotherClass{
private $mClass;
function __construct(){
global $m_class;
$this->mClass = $m_class;
}
}
#2
class AnotherClass{
private $mClass;
function __construct($mClassPassed){
$this->mClass = $mClassPassed;
}
}