Home  >  Article  >  Backend Development  >  What to do if php self reports an error

What to do if php self reports an error

藏色散人
藏色散人Original
2021-07-10 09:45:501863browse

Solution to php self error: First open the corresponding code file; then modify the content such as "$app = new App();$receiver = new Receiver($app);".

What to do if php self reports an error

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();  
 
  
}

What to do if php self reports an error

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!

Statement:
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