#50798 [Opn]: Unable to retrieve default value of argument of internal method with reflection
| From: | johannes@php.net | Date: | Tue, 19 Jan 2010 09:25:28 +0000 |
| Subject: | #50798 [Opn]: Unable to retrieve default value of argument of internal method with reflection | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-3750@lists.php.net to get a copy of this message | ||
ID: 50798
Updated by: johannes@php.net
Reported By: frederic dot hardy at mageekbox dot net
Status: Open
-Bug Type: Reflection related
+Bug Type: Documentation problem
Operating System: FreeBSD 7.1
PHP Version: 5.3.1
New Comment:
This behavior should be documented as is.
The reason is that PHP internally processes parameters differently.
Basically it works like func_num_args() und func_get_args() with the
implementation deciding what happens. We can't reflect on the
implementation in C level. What we'd need is to extend the argument info
structure to hold a pseudo-default-value just for the purpose of
reflection, we can't do that for 5.3 due to compatibility issues, I'm
not sure it's worth for later versions, especially as there are
functions where there is no "default value" but the decision depends on
"parameter available or not".
Previous Comments:
------------------------------------------------------------------------
[2010-01-19 07:41:15] frederic dot hardy at mageekbox dot net
Description:
------------
It's not possible to retrieve default value of an SPL method argument
with reflectionParameter class.
If we try to do that, an exception was throwed to inform us that it's
not possible.
So, i known that it's a known issue (bug 28114), but it's very annoying
and i would like to know the reason of this, or if there is a
workaround.
Reproduce code:
---------------
<?php
$method = new reflectionMethod('recursiveDirectoryIterator',
'setFlags');
foreach ($method->getParameters() as $parameter)
{
echo $parameter->getDefaultValue();
}
Expected result:
----------------
Something that it's not an exception.
Actual result:
--------------
PHP Fatal error: Uncaught exception 'ReflectionException' with message
'Cannot determine default value for internal functions' in
/usr/home/fch/tmp/class.php:7
Stack trace:
#0 /usr/home/fch/tmp/class.php(7):
ReflectionParameter->getDefaultValue()
#1 {main}
thrown in /usr/home/fch/tmp/class.php on line 7
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50798&edit=1