Req #32177 [Opn->Csd]: ReflectionException

From: Date: Sat, 29 Sep 2018 17:17:43 +0000
Subject: Req #32177 [Opn->Csd]: ReflectionException
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217290@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=32177&edit=1 ID: 32177 Updated by: nikic@php.net Reported by: pawel dot kozlowski at gmail dot com Summary: ReflectionException -Status: Open +Status: Closed Type: Feature/Change Request Package: Reflection related Operating System: Any PHP Version: 5.0.3 -Assigned To: +Assigned To: nikic Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2012-03-05 08:58:20] 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. ------------------------------------------------------------------------ [2005-03-03 16:29:24] 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 } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=32177&edit=1

« previous php.bugs (#217290) next »