Edit report at https://bugs.php.net/bug.php?id=45569&edit=1

 ID:                 45569
 Comment by:         kostia dot lukash at gmail dot com
 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:

Any news?


Previous Comments:
------------------------------------------------------------------------
[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

Reply via email to