Bug #62715 [NEW]: ReflectionParameter::isDefaultValueAvailable() wrong result
From: benjamin dot morel at strictcoding dot co dot uk
Operating system: CentOS 6.3, Windows 7
PHP version: 5.4.5
Package: Reflection related
Bug Type: Bug
Bug description:ReflectionParameter::isDefaultValueAvailable() wrong result
Description:
------------
When ReflectionParameter::isOptional() returns false, because other
parameters
after it are required, isDefaultValueAvailable() always return false, even
is
there actually is a default value.
I've read this older bug report: https://bugs.php.net/bug.php?id=41382
It looks like at that time, this behaviour had been considerer consistent.
I do think this should be revisited however, as in the example function
below,
there is absolutely no way with Reflection to get the default value for the
given parameter.
Reflection is a powerful tool for autowiring in Dependency Injection
containers,
where it is interesting to check whether default parameters are available,
regardless of their order.
Test script:
---------------
function test(PDO $a = null, $b = 0, array $c) {}
$r = new ReflectionFunction('test');
foreach ($r->getParameters() as $p) {
echo $p->getName();
echo " isDefaultValueAvailable: " .
var_export($p->isDefaultValueAvailable(), true) . "\n";
echo " isOptional: " . var_export($p->isOptional(), true) . "\n";
echo " allowsNull: " . var_export($p->allowsNull(), true) . "\n";
echo "\n";
}
Expected result:
----------------
a isDefaultValueAvailable: true
isOptional: false
allowsNull: true
b isDefaultValueAvailable: true
isOptional: false
allowsNull: true
c isDefaultValueAvailable: false
isOptional: false
allowsNull: false
Actual result:
--------------
a isDefaultValueAvailable: false
isOptional: false
allowsNull: true
b isDefaultValueAvailable: false
isOptional: false
allowsNull: true
c isDefaultValueAvailable: false
isOptional: false
allowsNull: false
--
Edit bug report at https://bugs.php.net/bug.php?id=62715&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=62715&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=62715&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=62715&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=62715&r=fixed
Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=62715&r=needdocs
Fixed in release: https://bugs.php.net/fix.php?id=62715&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=62715&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=62715&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=62715&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=62715&r=support
Expected behavior: https://bugs.php.net/fix.php?id=62715&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=62715&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=62715&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=62715&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=62715&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=62715&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=62715&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=62715&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=62715&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=62715&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=62715&r=mysqlcfg
Thread (9 messages)
- benjamin dot morel at strictcoding dot co dot uk