Php 调用另一个类并将内容放入构造函数中
我想我很难理解类中的构造函数。我在wordpress插件中编写了一个类。我现在想在另一个插件中使用这个类。这一切都很好。在我的职责范围内,我可以做新的课程等等,然后做我的事情。但是,我希望能够将一些值传递到这个新的类构造函数文件中,然后从构造函数传递变量。例如:Php 调用另一个类并将内容放入构造函数中,php,wordpress,class,constructor,Php,Wordpress,Class,Constructor,我想我很难理解类中的构造函数。我在wordpress插件中编写了一个类。我现在想在另一个插件中使用这个类。这一切都很好。在我的职责范围内,我可以做新的课程等等,然后做我的事情。但是,我希望能够将一些值传递到这个新的类构造函数文件中,然后从构造函数传递变量。例如: class why_wont_you_work { public foo1; public foo2; public function __construct() { $this->foo1= $othercla
class why_wont_you_work {
public foo1;
public foo2;
public function __construct() {
$this->foo1= $otherclassfunction['name'];
$this->foo2= $otherclassfunction['address'];
public function do_stuff() {
$otherclass = new $otherclass;
$otherclassfunction = $otherclass->otherclassfunction();
echo $this->foo1;
}
您可以创建一个接受参数的构造函数,并从创建参数的位置传递参数,就像函数的普通方法一样
class why_wont_you_work {
public foo1;
public foo2;
public function __construct($name, $address) {
$this->foo1= $name;
$this->foo2= $address;
public function do_stuff() {
$otherclass = new $otherclass;
$otherclassfunction = $otherclass->otherclassfunction();
echo $this->foo1;
}
$obj = new why_wont_you_work( "some name", "some address" );
您可以创建一个接受参数的构造函数,并从创建参数的位置传递参数,就像函数的普通方法一样
class why_wont_you_work {
public foo1;
public foo2;
public function __construct($name, $address) {
$this->foo1= $name;
$this->foo2= $address;
public function do_stuff() {
$otherclass = new $otherclass;
$otherclassfunction = $otherclass->otherclassfunction();
echo $this->foo1;
}
$obj = new why_wont_you_work( "some name", "some address" );
您可以创建一个接受参数的构造函数,并从创建参数的位置传递参数,就像函数的普通方法一样
class why_wont_you_work {
public foo1;
public foo2;
public function __construct($name, $address) {
$this->foo1= $name;
$this->foo2= $address;
public function do_stuff() {
$otherclass = new $otherclass;
$otherclassfunction = $otherclass->otherclassfunction();
echo $this->foo1;
}
$obj = new why_wont_you_work( "some name", "some address" );
您可以创建一个接受参数的构造函数,并从创建参数的位置传递参数,就像函数的普通方法一样
class why_wont_you_work {
public foo1;
public foo2;
public function __construct($name, $address) {
$this->foo1= $name;
$this->foo2= $address;
public function do_stuff() {
$otherclass = new $otherclass;
$otherclassfunction = $otherclass->otherclassfunction();
echo $this->foo1;
}
$obj = new why_wont_you_work( "some name", "some address" );