【发布时间】:2021-02-27 01:47:37
【问题描述】:
我遇到了如何附加到对象的问题。
我得到错误:
Uncaught Error: Cannot use object of type Anteris\Autotask\API\Contacts\ContactEntity as array in...
如果它删除带有MobilPhone 和Email if 语句的部分,它工作正常。
代码:
Create new contact
$contact = new Anteris\Autotask\API\Contacts\ContactEntity([
'id' => 0, // Autotask requires that new entities have an ID of 0
'companyID' => intval($Companyid),
'firstName' => $Fornavn,
'lastName' => $Efternavn,
'isActive' => 1,
'phone' => $Telefon,
]);
Check if MobilPhone filled out
if (empty($MobilTelefon)) {
} else {
$contact['mobilePhone'] = $MobilTelefon;
}
Check if Email filled out
if (empty($Email)) {
} else {
$contact['emailAddress'] = $Email;
}
Create in Autotask
$client->contacts()->create( $contact );
【问题讨论】:
-
嗯,消息很清楚,您正在尝试将对象用作数组,这是两个不同的东西。您不显示 Contact 实体的内容,因此很难提供帮助,但如果您在此实体中确实具有 mobilePhone 和 emailAddress 属性。然后你必须设置属性。让我们假设属性存在并且是公开的,您必须执行类似
$contact->emailAddress = $email之类的操作,而不是尝试将其用作数组。