php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32026 Can't call to function with paramArray in arg list definition
Submitted: 2005-02-19 11:09 UTC Modified: 2005-04-19 07:47 UTC
From: csaba at alum dot mit dot edu Assigned:
Status: Not a bug Package: COM related
PHP Version: 5CVS-2005-02-19 OS: Win XP Pro
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
40 + 7 = ?
Subscribe to this entry?

 
 [2005-02-19 11:09 UTC] csaba at alum dot mit dot edu
Description:
------------
If I try to make a call to a function where the function has a paramArray (a VB construct) in the definition, the call fails with (if the param array gets at least one argument).

For the unfamiliar, a paramArray in VB is an array (of variants) which consists of all the remaining arguments to the procedure.  As such, it must be the last declared parameter in the Function declaration.

Csaba Gabor from Vienna


Reproduce code:
---------------
Here is the PHP test code (menu.php):
<?php
    $oTool = new COM("Menu.Tool");
    $result = $oTool->ArgCount ("junk", 5, 13);
    print $result;
?>


Here is the code for the Menu.OCX file:
Public Function ArgCount(Arg1, ParamArray paArgRest())
    'counts the number of arguments passed, excluding Arg1
    ArgCount = UBound(paArgRest) + 1 - LBound(paArgRest)
End Function

Notes:
This was built using VB5CCE (the free (while available) VB, Control Creation Edition)
I have named my control Tool
I have named the Project Menu
I made the OCX into Menu.ocx
In the (VB5CCE) project I went to Project => Menu Properties => Component tab and set No Compatibility
After I made Menu.OCX, from the directory Menu.ocx resides in, I did: regsvr32 Menu.ocx


Here is the corresponding VBScript test file (menu.vbs) that works:
Set oTool = CreateObject("Menu.Tool")
result = oTool.ArgCount("junk", 5, 13)
MsgBox result

Expected result:
----------------
I expect to see a 2 printed or displayed (since there are two arguments after "junk")

Actual result:
--------------
menu.vbs produces the expected 2.

menu.php file fails with:
Cannot pass parameter 2 by reference in C:\Testing\ParamArray\menu.php on line 3

If the paramArray gets no elements
    $result = $oTool->ArgCount ("junk");
then I get the expected 0

I've inserted a
    com_print_typeinfo($oTool) and received (there was other code in menu.ocx):
        /* DISPID=1610809344 */
        /* VT_VARIANT [12] */
        function ArgCount(
                /* VT_PTR [26] [in][out] --> VT_VARIANT [12]  */ &$Arg1,
                /* VT_PTR [26] [in][out] --> ? [27]  */ &$paArgRest
                )
        {
        }

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-18 18:42 UTC] wez@php.net
Please paste the IDL for that method into this bug report.
You can view the IDL using the OleView tool.
 [2005-04-19 07:47 UTC] wez@php.net
I re-read your report; what you're seeing is the expected behaviour.  The IDL for your method expects a variant followed by a safearray of variants.  Both of these are in/out parameters, which means that they are passed by reference.
Your code was trying to pass constants as parameters, and this  is illegal (think about it: you can't allow a function to modify a constant).

PHP can't tell from the IDL that VB has declared the function as having variable arguments; this concept does not exist in COM, so you must create an array manually and pass additional arguments in through that array.

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