0

I'm using PHP to work with a COM object and one of the COM object's function's parameters is an "out" parameter. How does PHP work with these?

Example (ModifyParam could do anything, like output the word of the day or provide an object):

$MyCom = new COM("APPLib.APP");

$outParam;
//APP.ModifyParam(out object pParam)
$MyCom->ModifyParam($outParam);

var_dump($outParam); //NULL

The example is based on actual code which outputs what would be an object array, or an array of strings. The real code isn't outputting the list though.

1 Answer 1

1

As far as I know (you can correct me if I'm wrong here) - the [out] parameter means the variable to store the results. So if you have this method in the COM object:

GetUserInfo([in] long machineID, [out] long* userID, [out] BSTR* userName)

The [in] parameter means the argument, the [out] parameter are result variables that will get written, much like how MySQLi::bind_result() method works. Example code to use the method above (assuming the COM object has been set appropriately):

$obj = new COM('Namespace.Class');

// This is the [in] parameter, the machine number we wanted to inspect.
$machineID = 1

// Define [out] variables with the correct type, according to the API.
$userID = 0;
$userName = '';

// Call the COM method.
$obj->GetUserInfo($machineID, $userID, $userName);

// Print the results.
echo "User ID: $userID<br />";
echo "User Name: $userName";
Sign up to request clarification or add additional context in comments.

1 Comment

It's been so long since I've worked on this. I can't recall what the problem was at the time. Thank you for your explanation anyway, and maybe it'll come in handy some time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.