Page 1 of 1

parameter passing by ref to a COM function

Posted: Wed Jun 16, 2004 7:11 pm
by alanchinese
hi, there is a COM function having the following definition (.NET Interop):

public virtual new void CALL(System.String SubroutineName, @params);

in C#.NET, i am able to use the function by....
string param1 = "", param2 = "", param3 = "";
Object[] callParams = {param1, param2, param3};
comobj.Call("called.sub", ref callParams);

i tried the similar things in PHP....
$param1 = ""
$param2 = ""
$param3 = ""
$callParams = array($param1, $param2, $param3);
$comobj->Call("called.sub", $callParams); // how do i set up the by ref passing?

i got error when opening up the page:
PHP Warning: (null)(): Invoke() failed: Exception occurred.\r\n <b>Source</b>: OBjEX.jConnectObject.33 <b>Description</b>: Method : Call : OBJEX.GET.LIST.SUB\r\n\r\nThe subroutine was terminated abnormally.

is it an error from PHP? or from COM?

Posted: Thu Jun 17, 2004 12:00 am
by Weirdan
passing by ref is done in php like this:

Code: Select all

somefunc($by_val, &$by_ref); // note the ampersand

Posted: Thu Jun 17, 2004 3:57 am
by alanchinese
"Call-time pass-by-reference has been deprecated"
is it good to still use "&" for reference passing?

Posted: Thu Jun 17, 2004 5:09 am
by Weirdan
PHP Manual wrote: Starting with PHP 5, PHP will automatically detect methods that accept parameters by reference, and will automatically convert regular PHP variables to a form that can be passed by reference. This means that you can call the method very naturally; you needn't go to any extra effort in your code.

In PHP 4, to pass parameters by reference you need to create an instance of the VARIANT class to wrap the byref parameters.
It does mean I was wrong.