Call a class inside another class in PHP

后端 未结 2 2026
清酒与你
清酒与你 2021-02-04 08:58

Hey there I\'m wondering how this is done as when I try the following code inside a function of a class it produces some php error which I can\'t catch

public $t         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-02-04 09:33

    You're problem is with this line of code:

    public $tasks;
    $this->tasks = new tasks();
    $this->tasks->test();
    $this->showPanel();
    

    The public keyword is used in the definition of the class, not in a method of the class. In php, you don't even need to declare the member variable in the class, you can just do $this->tasks=new tasks() and it gets added for you.

提交回复
热议问题