Home > Article > Backend Development > What is the difference between use and include in php
Difference: include is an imported file. If the file cannot be found (failed to load the file), include will generate a warning (E_WARNING), and the script will continue to execute after the error occurs; while use uses a namespace, which is equivalent to When using the import package in Java, you need to write the full space name and class name.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
The difference between use and include in PHP
include is an import file. If the file cannot be found, include will report a warning and continue execution.
use uses a namespace, which is equivalent to the import package in java, provided that the files in the package need to be required or included in advance.
namespace namespace, equivalent to package in java, defines a package
When using it, you need to write the full space name and class name later, such as the namespace Person1/Person; where Person1 is Namespace, Person is the class name.
Extended information: The difference between require and include in php
nclude has a return value, but require does not.
include fails to load the file , a warning (E_WARNING) is generated and the script continues execution after the error occurs. So include is used when you want to continue execution and output results to the user.
require will generate a fatal error (E_COMPILE_ERROR) when loading fails, and the script will stop executing after the error occurs. Generally used when subsequent code depends on the loaded file.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What is the difference between use and include in php. For more information, please follow other related articles on the PHP Chinese website!