php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70294 ReflectionException getCode should return a non-zero code
Submitted: 2015-08-18 16:10 UTC Modified: -
From: mattsch at gmail dot com Assigned:
Status: Open Package: Reflection related
PHP Version: 5.6.12 OS: Gentoo
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
27 + 16 = ?
Subscribe to this entry?

 
 [2015-08-18 16:10 UTC] 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)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-18 20:30 UTC] 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.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Sep 23 11:01:27 2019 UTC