ReflectionException 类

(PHP 5, PHP 7, PHP 8)

简介

ReflectionException 类。

类摘要

ReflectionException extends Exception {
/* 属性 */
protected string $message ;
protected int $code ;
protected string $file ;
protected int $line ;
/* 继承的方法 */
final public Exception::getMessage ( ) : string
final public Exception::getPrevious ( ) : Throwable
final public Exception::getCode ( ) : mixed
final public Exception::getFile ( ) : string
final public Exception::getLine ( ) : int
final public Exception::getTrace ( ) : array
final public Exception::getTraceAsString ( ) : string
public Exception::__toString ( ) : string
final private Exception::__clone ( ) : void
}

User Contributed Notes

temirkhan.nasukhov 18-Apr-2019 11:50
Note that this exception is unchecked even if it is not based on RuntimeException.  Such error must lead to direct fixes in code and not in catch-handle of situation.

Also keep in mind that IDE (mine is Phpstorm 2018.3.4) inspections will highlight it for that reason so do not create phpdoc with throws for any Runtime exceptions.

<?php

/**
 * This way is wrong
 *
 * @throws \ReflectionException
 */
function createReflection()
{
    return new \
ReflectionClass('invalid argument');
}

/**
 * This way is fine(I don't mean the code of course)
 */
function createReflection()
{
    return new \
ReflectionClass('invalid argument');
}
PHP8中文手册 站长在线 整理 版权归PHP文档组所有