我正在使用一个数组在 foreach 语句中记录关键信息以供以后使用,我将数组设置在页面顶部以确保它在脚本中的所有函数中都可用。
我已经测试了该数组是否已设置,并且它似乎在 try catch 语句之外工作,请参阅下面的注释代码。
$completeClients = array();
if($can_synchronise === true)
{
$success = sync_to_client($package, $client);
try
{
if($success)
{
$completeClients[] = "Sync to ".$client->getName()." has completed";
}
else
{
$completeClients[] = "Sync to ".$client->getName()." has failed";
}
}
catch(Exception $ex)
{
logMsg("Unable to save client data reason: ". $ex->getMessage(), STATUS_ERROR , $client->getAddress());
}
exit( EXIT_OK );//Exit the child process
}
}
else
{
**// The array is set correctly when called here**
$completeClients[] = "Sync to ".$client->getName()." has failed";
}
我已经打印了数组,当它在 try catch 语句中被调用时,它看起来像:
Array
(
[0] => Sync to TPSDEV_PHILIPS_TWO has completed
)
Array
(
[0] => Sync to TPSDEV_TC_Client2 has completed
)
Array
(
)
它应该看起来像
Array
(
[0] => Sync to TPSDEV_PHILIPS_TWO has completed
)
Array
(
[0] => Sync to TPSDEV_PHILIPS_TWO has completed
[1] => Sync to TPSDEV_TC_Client2 has completed
)
Array
(
[0] => Sync to TPSDEV_PHILIPS_TWO has completed
[1] => Sync to TPSDEV_TC_Client2 has completed
)
你们有什么想法吗?我难住了。