PHP、COM对象和out参数


PHP, COM objects, and out parameters

我使用PHP处理COM对象,COM对象函数的参数之一是"out"参数。PHP是如何处理这些问题的?

示例(ModifyParam可以做任何事情,比如输出当天的单词或提供对象):

$MyCom = new COM("APPLib.APP");
$outParam;
//APP.ModifyParam(out object pParam)
$MyCom->ModifyParam($outParam);
var_dump($outParam); //NULL

该示例基于实际代码,该代码输出对象数组或字符串数组。然而,真正的代码并没有输出列表。

据我所知(如果我错了,你可以纠正我)-[out]参数意味着存储结果的变量。因此,如果你在COM对象中有这个方法:

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

[in]参数表示参数,[out]参数是将被写入的结果变量,很像MySQLi::bind_result()方法的工作方式。使用上述方法的示例代码(假设COM对象已适当设置):

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