Note that you can use a fully qualified name to access any global class, function, or constant, such as strlen (), Exception, or INI_ALL. {Code...} Can extendsException be directly written as extendsException? That is to say, the system functions or classes can be written... note that you can use a fully qualified name to access any global class, function, or constant, such as \ strlen (), \ Exception, or \ INI_ALL.
class APIConnectionException extends \Exception { public $isResponseTimeout; function __construct($message, $isResponseTimeout = false) { parent::__construct($message); $this->isResponseTimeout = $isResponseTimeout; }}
Hereextends \ExceptionCan be directly writtenextends Exception? That is to say, the system functions or classes can be written\ExceptionOr\strlen()Can also be writtenExceptionOrstrlen()?
The answer is yes or no. If you want to add it, please add it!
Reply content:
Note that you can use a fully qualified name to access any global class, function, or constant, such as \ strlen (), \ Exception, or \ INI_ALL.
class APIConnectionException extends \Exception { public $isResponseTimeout; function __construct($message, $isResponseTimeout = false) { parent::__construct($message); $this->isResponseTimeout = $isResponseTimeout; }}
Hereextends \ExceptionCan be directly writtenextends Exception? That is to say, the system functions or classes can be written\ExceptionOr\strlen()Can also be writtenExceptionOrstrlen()?
The answer is yes or no. If you want to add it, please add it!
In your example, the answer is "yes"
If PHP does not specify a namespace for a class or function, its namespace is the current namespace by default, and the current namespace of this Code is empty, it is the root space.\So you can either write or not, because they all point to a space.
If you declare a namespace before the class
namespace Some\Namespace;
There will be a difference, for example\ExceptionThe previous backslash is removed. According to the preceding principle, the current namespace becomesSome\NamespaceSo it will goSome\Namespace\ExceptionIn the end, an error that you cannot find will be thrown.