Bug #70294 [Opn]: ReflectionException getCode should return a non-zero code
| From: | cmb@php.net | Date: | Tue, 14 Sep 2021 13:00:10 +0000 |
| Subject: | Bug #70294 [Opn]: ReflectionException getCode should return a non-zero code | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-236588@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70294&edit=1
ID: 70294
Updated by: cmb@php.net
Reported by: mattsch at gmail dot com
Summary: ReflectionException getCode should return a non-zero
code
Status: Open
Type: Bug
Package: Reflection related
Operating System: Gentoo
PHP Version: 5.6.12
Block user comment: N
Private report: N
New Comment:
I have to agree that using a single exception type with the same
code for all of this is not the best solution, but I think you can
probe in advance for nearly all cases (e.g. in this case you can
check function_exists('foo)) in advance, what appears to be
preferable anyway.
Previous Comments:
------------------------------------------------------------------------
[2015-08-18 20:30:54] mattsch at gmail dot com
Correction: If you call ReflectionClass on a class that does not exist, getCode returns -1. If you
call ReflectionProperty on a property that doesn't exist, getCode returns 0 so
ReflectionException::getCode is still useless in its current state.
------------------------------------------------------------------------
[2015-08-18 16:10:56] mattsch at gmail dot com
Description:
------------
When a ReflectionException is thrown for any reflection class, an exception code is not set (i.e. it
always returns 0). This makes it quite difficult to identify what caused the exception. As a
result, I am forced to parse the exception message to determine what went wrong instead of relying
on a constant from the getCode method.
Test script:
---------------
<?php
try {
$reflectionFunction = new ReflectionFunction('foo');
} catch(Exception $e){
var_dump($e->getCode());
}
Expected result:
----------------
A non-zero code.
Actual result:
--------------
int(0)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70294&edit=1