Seemingly redundant reflection methods with no documentation
There are several seemingly redundant methods in php ReflectionParameter:
public bool isDefaultValueAvailable ( void ) public bool isOptional ( void )
Furthermore, there is no further useful documentation to differentiate these.
Also related but different:
public bool allowsNull ( void )
Here's an example of how they respond:
$ cat params.php <?php function example( $a, object $b, array $c, object $d = NULL, array $e = NULL ){} $rf = new ReflectionFunction("example"); foreach ($rf->getParameters() as $param) { echo $param->getName()."\n"; echo " allowsNull: "; var_dump($param->allowsNull()); echo " isDefaultValueAvailable: "; var_dump($param->isDefaultValueAvailable()); echo " isOptional: "; var_dump($param->isOptional()); } $ php params.php a allowsNull: bool(true) isDefaultValueAvailable: bool(false) isOptional: bool(false) b allowsNull: bool(false) isDefaultValueAvailable: bool(false) isOptional: bool(false) c allowsNull: bool(false) isDefaultValueAvailable: bool(false) isOptional: bool(false) d allowsNull: bool(true) isDefaultValueAvailable: bool(true) isOptional: bool(true) e allowsNull: bool(true) isDefaultValueAvailable: bool(true) isOptional: bool(true)
The difference, it turns out, is with internal functions:
$ php -r '$p=new ReflectionParameter("strpos","offset");var_dump($p->isOptional(),$p->isDefaultValueAvailable());' bool(true) bool(false)
Apparently, this is so PHP doesn't have to reveal the default values of its functions? What use is this, then?