必须先调用COM对象方法才能在函数内部使用它

时间:2016-04-14 14:44:43

标签: php com

我正在学习如何在PHP中使用COM对象和dll,而且我遇到了一些看起来不太合适的东西。这有效:

$comobj = new COM("COMLoggerClass");
echo 'here1';
$comobj->Log('test1');
echo 'here2';

function test($pComObj)
{
    echo 'here4';
    $pComObj->Log('test2');
    echo 'here5';
}

echo 'here3';
test($comobj);

这不是:

$comobj = new COM("COMLoggerClass");
echo 'here1';
//$comobj->Log('test1');
echo 'here2';

function test($pComObj)
{
    echo 'here4';
    $pComObj->Log('test2');
    echo 'here5';
}

echo 'here3';
test($comobj);

第二行会在$pComObj->Log('test2');行上导致致命错误,并显示以下消息:

Cannot pass parameter 1 by reference

基本上,在这种情况下,COM对象的方法必须在创建对象的范围内使用一次才能在方法中使用它。但这没有任何意义。这里到底发生了什么?

0 个答案:

没有答案
相关问题