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

What to do if php self reports an error

藏色散人
Release: 2023-03-11 12:14:01
Original
1918 people have browsed it

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

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);
Copy after login

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!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template