如何在.php中的类中实例化一个类
问题描述:
我是OOP的新手,我不知道为什么这不起作用.在类中实例化一个类不是可以的.我已经尝试过使用方法中包含的文件进行操作,但并没有做任何更改.
I'm new to OOP and I can't figure out why this isn't working. Is it not ok to instantiate a class with in a class. I've tried this with included file with in the method and it didn't make a change.
include('Activate.php');
class First {
function __construct() {
$this->activate();
}
private function activate() {
$go = new Activate('Approved');
}
}
$run = new First();
答
好的,我知道了我的问题.我的代码有两个错误.一种是将我的方法设置为私有方法,其次,我在发送给类的 $ parms
中出现错误.
Okay I figured out my issue. My code had two errors. One that being my method was set to private and secondly I had an error in my $parms
that I was sending to the class.
include('Activate.php');
class First {
function __construct() {
$this->activate();
}
private function activate() {
$go = new Activate('Approved');
}
}
$run = new First();