#50798 [Opn->Csd]: Unable to retrieve default value of argument of internal method with reflection

From: Date: Wed, 20 Jan 2010 11:41:53 +0000
Subject: #50798 [Opn->Csd]: 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-3760@lists.php.net to get a copy of this message
ID: 50798 Updated by: degeberg@php.net Reported By: frederic dot hardy at mageekbox dot net -Status: Open +Status: Closed Bug Type: Documentation problem Operating System: FreeBSD 7.1 PHP Version: 5.3.1 New Comment: This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. Previous Comments: ------------------------------------------------------------------------ [2010-01-20 11:41:23] svn@php.net Automatic comment from SVN on behalf of degeberg Revision: http://svn.php.net/viewvc/?view=revision&revision=293765 Log: Fixed PHP bug #50798 (Unable to retrieve default value of argument of internal method with reflection) and added example to ReflectionParameter::getDefaultValue(). ------------------------------------------------------------------------ [2010-01-19 09:25:28] johannes@php.net 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". ------------------------------------------------------------------------ [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

« previous php.doc.bugs (#3760) next »