#32026 [Fbk->Bgs]: Can't call to function with paramArray in arg list definition

From: Date: Tue, 19 Apr 2005 05:47:49 +0000
Subject: #32026 [Fbk->Bgs]: Can't call to function with paramArray in arg list definition
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-77848@lists.php.net to get a copy of this message
ID: 32026 Updated by: wez@php.net Reported By: csaba at alum dot mit dot edu -Status: Feedback +Status: Bogus Bug Type: COM related Operating System: Win XP Pro PHP Version: 5CVS-2005-02-19 New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2005-04-18 18:42:58] wez@php.net Please paste the IDL for that method into this bug report. You can view the IDL using the OleView tool. ------------------------------------------------------------------------ [2005-02-19 11:09:13] 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 ) { } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=32026&edit=1

« previous php.bugs (#77848) next »