Home > Article > Backend Development > What to do if php self reports an error
Solution to php self error: First open the corresponding code file; then modify the content such as "$app = new App();$receiver = new Receiver($app);".
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
What should I do if php self reports an error?
php new self() error
public function t2() { $receiver = new self(); }
Solution:
The error message is already very It’s obvious: __construct() lacks parameters. The code you posted does not pass in $app. I have not used TP6, but in a framework like this, the way to obtain an object is to use a container. When using a container, it will Dependency is automatically injected (that is, $app is automatically instantiated). If you use new, dependencies will not be injected.
So when using a container, you can do this: $receiver = invoke('xxx');
When using the new method, you can do this:
$app = new App(); $receiver = new Receiver($app);
For details, please refer to TP6 Documentation: https://www.kancloud.cn/manual/thinkphp6_0/1037489
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What to do if php self reports an error. For more information, please follow other related articles on the PHP Chinese website!