php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #50798 Unable to retrieve default value of argument of internal method with reflection
Submitted: 2010-01-19 07:41 UTC Modified: 2010-01-20 11:41 UTC
From: frederic dot hardy at mageekbox dot net Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.3.1 OS: FreeBSD 7.1
Private report: No CVE-ID: None
 [2010-01-19 07:41 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-19 09:25 UTC] 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-20 11:41 UTC] 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-20 11:41 UTC] degeberg@php.net
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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 14:01:29 2024 UTC