Doc #52909 [Asn]: ReflectionMethod::getParameters() return incorrect number of arguments

From: Date: Thu, 23 Sep 2010 04:39:19 +0000
Subject: Doc #52909 [Asn]: ReflectionMethod::getParameters() return incorrect number of arguments
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-5114@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=52909&edit=1 ID: 52909 Updated by: aharvey@php.net Reported by: frederic dot hardy at mageekbox dot net Summary: ReflectionMethod::getParameters() return incorrect number of arguments Status: Assigned Type: Documentation Problem Package: PHAR related Operating System: FreeBSD 8.0 PHP Version: 5.3.3 Assigned To: aharvey Block user comment: N New Comment: The reason for this is that Phar and PharData actually use the same function for their __construct implementations -- internally it calls instanceof_function() to figure out whether it's constructing a Phar or PharData object and then has some if statements to handle things from there. There's no distinct arginfo for the PharData implementation, so reflection has no way of distinguishing the three parameter Phar constructor from the four parameter PharData constructor. I'll make the proto comment in phar_object.c a little clearer (and remove the extra vim fold that doesn't do anything useful). Beyond that, the manual's correct for Phar::__construct() but not for PharData::__construct() (which is currently documented as accepted two parameters when it actually accepts four), so I'll fix that up. I don't see any way of getting reflection to do the right thing short of refactoring the function into two -- which might be the right thing to do anyway, but is a decision for Greg or Marcus to make. Previous Comments: ------------------------------------------------------------------------ [2010-09-22 23:44:20] tony2001@php.net The docs and the comment in the sources are apparently wrong and need fixing. ------------------------------------------------------------------------ [2010-09-22 23:17:15] frederic dot hardy at mageekbox dot net Description: ------------ I'm using PHP 5.3.3 and PHP trunk under FreeBSD 8.0 p4. I'm trying to retrieve arguments of phar::__construct() with ReflectionMethod::getArguments(). Phar::__construct() take only 3 arguments, but my script return 4 arguments, as if PharData::__construct() was used instead of Phar::__construct() by the reflection API. In fact, ext/phar_object.c contains the following comments : /* {{{ proto void Phar::__construct(string fname [, int flags [, string alias]]) * Construct a Phar archive object * {{{ proto void PharData::__construct(string fname [[, int flags [, string alias]], int file format = Phar::TAR]) * Construct a PharData archive object */ PHP_METHOD(Phar, __construct) { ... } Test script: --------------- <?php $method = new reflectionMethod('phar', '__construct'); foreach ($method->getParameters() as $parameter) { var_dump($parameter->getName()); var_dump($parameter->isOptional()); var_dump($parameter->isDefaultValueAvailable()); } ?> Expected result: ---------------- string(8) "filename" bool(false) bool(false) string(5) "flags" bool(true) bool(false) string(5) "alias" bool(true) bool(false) Actual result: -------------- string(8) "filename" bool(false) bool(false) string(5) "flags" bool(true) bool(false) string(5) "alias" bool(true) bool(false) string(10) "fileformat" bool(true) bool(false) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52909&edit=1

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