php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52183 Reflectionfunction reports invalid number of arguments for function aliases
Submitted: 2010-06-25 12:50 UTC Modified: 2010-06-26 18:04 UTC
From: andreas dot streichardt at globalpark dot com Assigned: felipe (profile)
Status: Closed Package: Reflection related
PHP Version: 5.3.2 OS: Linux
Private report: No CVE-ID: None
 [2010-06-25 12:50 UTC] andreas dot streichardt at globalpark dot com
Description:
------------
When defining a function alias internally in PHP, PHP_FALIAS requires an arginfo 
as the third parameter.

For example gzwrite() is internally represented as a function alias to fwrite():

PHP_FALIAS(gzwrite,             fwrite,                 NULL)

Here however the argument info is not provided. This leads to the fact that the 
reflection api can't extract the parameters of gzwrite.

Why does an FALIAS require an arginfo? Couldn't it just take the argument info 
of the alias function if the arginfo is null? The impact is that you can't 
determine the required arguments from the gzwrite function. I hacked the code 
and added the arginfo stuff and the reflection api immediatly noticed that 
gzwrite requires 2 parameters. We are doing massive static code analysis and our 
code analysis returns bogus results due to the fact that the reflection api 
can't report the real arguments of a function.

Test script:
---------------
<?php
foreach (array("gzwrite","fwrite") as $function)
{
  $refl=new ReflectionFunction($function);
  var_dump($refl->getNumberOfRequiredParameters());
  var_dump($refl->getNumberOfParameters());
}
?>

Expected result:
----------------
int(2)
int(3)
int(2)
int(3)


Actual result:
--------------
int(0)
int(0)
int(2)
int(3)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-26 17:27 UTC] felipe@php.net
To get the arginfo from original function will decrease the performance and will lead to change the internal function structure...
I think is better to add the arginfo as the normal functions for the aliases.
 [2010-06-26 18:03 UTC] felipe@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=300764
Log: - Fixed bug #52183 (Reflectionfunction reports invalid number of arguments for function aliases)
 [2010-06-26 18:04 UTC] felipe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: felipe
 [2010-06-26 18:04 UTC] felipe@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 04:01:31 2024 UTC