Req #45569 [Com]: Suggestions for reflection API
| From: | st dot mueller at dzh-online dot de | Date: | Wed, 05 Feb 2014 17:48:14 +0000 |
| Subject: | Req #45569 [Com]: Suggestions for reflection API | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-184169@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=45569&edit=1
ID: 45569
Comment by: st dot mueller at dzh-online dot de
Reported by: missingno at ifrance dot com
Summary: Suggestions for reflection API
Status: Open
Type: Feature/Change Request
Package: Reflection related
Operating System: *
PHP Version: 5.2CVS-2008-07-20 (snap)
Block user comment: N
Private report: N
New Comment:
Interesting, this issue exists for 3,5 years now and nobody seems to care. This is sad. Can at least
anyone comment on this, whether this would be an acceptable addition or not? I see there might be
problem concerning method namings and BC but what about introducing two new mehtods like
getConstantReflector($constant) and getConstantReflectors()?
I really need this feature and use a very expensive workaround for now. I would even try to add a
patch for this.
Cheers,
Steve
Previous Comments:
------------------------------------------------------------------------
[2012-03-20 12:01:40] kostia dot lukash at gmail dot com
Any news?
------------------------------------------------------------------------
[2008-07-20 11:40:26] missingno at ifrance dot com
Description:
------------
I'm only submitting a suggestion made by Niels Jaeckel on the Reflection API which I think may
be valuable.
See http://docs.php.net/reflection for the original
post.
Niels suggested that a new object be created called ReflectionConstant.
ReflectionClass::getConstants() [and maybe also ReflectionExtension::getConstants()] should be
changed to return an array of such objects.
This way, it would be possible to read DocComments for class constants.
Also, there is currently no way to retrieve the type hint of a given parameter (in
ReflectionParameter). Maybe I should fill another bug report for this one ?
Reproduce code:
---------------
<?php
class MyCharacter { /* some stuff here */ }
class MyString {
/** ASCII string */
const TYPE_ASCII = 1;
/** Unicode string */
const TYPE_UNICODE = 2;
public function __construct(MyCharacter $char, $type) {
/* do something useful here */
}
}
$class = new ReflectionClass('MyString');
foreach ($class->getConstants as $constant) {
echo $constant->getName()." = ".$constant->getValue()."
(".$contant->getDocComment().")\r\n";
}
echo "\r\n";
$method = new ReflectionMethod('MyString', '__construct');
foreach ($method->getParameters as $parameter) {
echo "Type hint for ".$param->getName()." is
".$param->getTypeHint().".\r\n";
}
?>
Expected result:
----------------
I would expect something like the following to be echoed:
TYPE_ASCII = 1 (ASCII string)
TYPE_UNICODE = 2 (Unicode string)
Type hint for char is MyCharacter.
Type hint for type is .
// getTypeHint() could return NULL or FALSE if no type hint was given.
Actual result:
--------------
This is currently no way of retrieving the DocComment of a class constant. There is also no way of
retrieving information about type hinting in methods' parameters.for
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=45569&edit=1