Home > PHP Framework > ThinkPHP > How to solve thinkphp new self() error problem

How to solve thinkphp new self() error problem

藏色散人
Release: 2021-11-23 15:52:35
forward
1841 people have browsed it

The followingthinkphp frameworkThe tutorial column will introduce to you how to solve the thinkphp new self() error problem. I hope it will be helpful to friends in need!

Specific problem description:

public function t2()  
{  
  
  $receiver = new self();  
 
  
}
Copy after login

How to solve thinkphp new self() error problem

Framework thinkphp6

Solution:

The error message is already obvious: __construct() is missing parameters. The code you posted does not pass in $app. I have not used TP6, but in a framework like this, the method of obtaining an object is When using a container, it will automatically inject dependencies (that is, automatically instantiate $app). If you use new, dependencies will not be injected.

So when using the container, you can do this: $receiver = invoke('xxx');

When using the new method, you can do this:

$app = new App();
$receiver = new Receiver($app);
Copy after login

For details, please refer to the documentation of TP6: https://www.kancloud.cn/manual/thinkphp6_0/1037489

Recommended: "The latest 10 thinkphp video tutorials"

The above is the detailed content of How to solve thinkphp new self() error problem. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
ThinkPHP Why use composer?
From 1970-01-01 08:00:00
0
0
0
thinkphp versions supported by php6
From 1970-01-01 08:00:00
0
0
0
thinkphp upload files
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template