Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 调用另一个类并将内容放入构造函数中_Php_Wordpress_Class_Constructor - Fatal编程技术网

Php 调用另一个类并将内容放入构造函数中

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

我想我很难理解类中的构造函数。我在wordpress插件中编写了一个类。我现在想在另一个插件中使用这个类。这一切都很好。在我的职责范围内,我可以做新的课程等等,然后做我的事情。但是,我希望能够将一些值传递到这个新的类构造函数文件中,然后从构造函数传递变量。例如:

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" );