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";
精彩评论