Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从set_exception_处理程序函数获取异常名称_Php_Oop_Exception_Exception Handling - Fatal编程技术网

Php 从set_exception_处理程序函数获取异常名称

Php 从set_exception_处理程序函数获取异常名称,php,oop,exception,exception-handling,Php,Oop,Exception,Exception Handling,我有几个例外,例如: fooException extends Exception{} barException extends Exception{} tarException extends Exception{} 下面是异常处理程序 set_exception_handler('get_exceptions'); function get_exceptions($msg){ # how to get the exception name here like # f

我有几个例外,例如:

fooException extends Exception{}
barException extends Exception{}
tarException extends Exception{}
下面是异常处理程序

 set_exception_handler('get_exceptions');

  function get_exceptions($msg){
    # how to get the exception name here like
    # fooException barException
  }
示例错误

 if(0){
    throw new fooException;  
 }

 if(!1){
   throw new barException;  
 }
现在,在get_exceptions函数中,我正在尝试但无法获得抛出的异常类型,而不是消息、代码和整个数据。只有类的名称,比如fooException或barException,是否只需要获取触发的异常的名称?

试试看

$exceptionClass = get_class($msg);
试一试


不。我试过了,但没有成功。另外,您要的是类名,而我要的是异常名。那么,请定义异常名。这是怎么一回事?在您的问题中,您只需要类的名称,如fooException或barException。通过使用get_classWell,我尝试过这种方法,我告诉你。它完全没有回声。我试过了,但没有成功。另外,您要的是类名,而我要的是异常名。那么,请定义异常名。这是怎么一回事?在您的问题中,您只需要类的名称,如fooException或barException。通过使用get_classWell,我尝试过这种方法,我告诉你。它完全没有回声