php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #32177 ReflectionException
Submitted: 2005-03-03 16:29 UTC Modified: 2018-09-29 17:17 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: pawel dot kozlowski at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Reflection related
PHP Version: 5.0.3 OS: Any
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: pawel dot kozlowski at gmail dot com
New email:
PHP Version: OS:

 

 [2005-03-03 16:29 UTC] pawel dot kozlowski at gmail dot com
Description:
------------
I?m trying to use Reflection API. I works great, but I?ve some remarks regarding ReflectionException. Calling ReflectionParameter::getClass() will raise an exception when class definition isn?t already included. That?s fine, it?s an expected behavior. The problem is that I have no way to get the missing class name. Ok, I could parse message string, but this way it becomes (unintentionally) part of  the public API. What do You think about having sth like

Class ReflectionExceptionClassNotDefined extends ReflectionException
{
	public string getClassName();

}


Reproduce code:
---------------
class A
{
    public function __construct(B $b)
    {
       $this->b = $b;
    }
}

$rc = new ReflectionClass('A');
$rconstr = $rc->getConstructor();
$rparams = $rconstr->getParameters();

try
{
   $paramclass = $rparams[0]->getClass();
}
catch (ReflectionException $e)
{
   //no way to get 'B' name here, without parsing msg string
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-20 14:08 UTC] jani@php.net
-Package: Feature/Change Request +Package: Reflection related
 [2012-03-05 08:58 UTC] daanleduc at hotmail dot com
Had the same problem fixed it like this ->

http://stackoverflow.com/questions/4513867/php-reflection-get-method-parameter-
type-as-string/9500359#9500359

Would be better if there is an getClassName on reflection parameter.
 [2017-10-24 06:54 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: johannes +Assigned To:
 [2018-09-29 17:17 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2018-09-29 17:17 UTC] nikic@php.net
Since PHP 7 it's possible to get the type declaration as string. Instead of $param->getClass()->getName() you'd write either (string) $param->getType() or $param->getType()->getName(), depending on whether you need PHP 7.0 compatibility.

It sound like this should cover the described use-case, so I'm closing this issue. If that's not the case, please feel free to reopen the issue.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC