parameter passing by ref to a COM function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alanchinese
Forum Newbie
Posts: 11
Joined: Fri Jun 11, 2004 4:53 pm

parameter passing by ref to a COM function

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

passing by ref is done in php like this:

Code: Select all

somefunc($by_val, &$by_ref); // note the ampersand
alanchinese
Forum Newbie
Posts: 11
Joined: Fri Jun 11, 2004 4:53 pm

Post by alanchinese »

"Call-time pass-by-reference has been deprecated"
is it good to still use "&" for reference passing?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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.
Post Reply