简体   繁体   中英

PHP, COM objects, and out parameters

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.

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";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM