私のGoogleカレンダーアカウントにイベントをインポートしようとしましたが、エラーのためコードをインポートできません:Cannot use object of type Event as array
これは私のスクリプトの2149行にあります。イベントタイプのオブジェクトを配列として使用できません
$exported_events = array();
foreach($events as $event_id => $event)
{
$event = new Event();
$event->setSummary($event->location);
$event->setLocation($event->location);
$start = new EventDateTime();
$start->setDateTime($event['starts']); // Line 2149
$event->setStart($start);
$end = new EventDateTime();
$end->setDateTime((object) $event['ends']);
$event->setEnd($end);
$attendees = array();
foreach($event['people'] as $i => $person)
{
$attendee = new EventAttendee();
$attendee->setEmail($person->email);
$attendees[] = $attendee;
$event->attendees = $attendees;
}
$createdEvent = $service->events->insert('primary', $event);
$calendar_event_id = $createdEvent->getId();
if(!is_null($calendar_event_id))
{
$exported_events[] = $event_id;
}
}
さて、私のforeach
ループは$events
アレイの上を歩くように、それは私は$event->location
にそれを変更$event['location']
でエラーが発生しました、今では(アレイが印刷されるアレイの項目であるライン2149上でエラーをスローページの下)と私は$event->starts
にそれを私にこのエラーをスローされます:Undefined property: Event::$starts
を入れても(object) $event['starts']
を入れてtはまだ動作しません。
どうすれば動作させることができますか? var_dump($event['starts'])
は文字列として返します。各$event
あたりの
配列:
Array
(
[location] => Some location in the US
[starts] => 2012-03-13T10:00:00
[ends] => 2012-03-13T14:00:00
[people] => Array
(
[0] => Array
(
[name] => Joan Uton
[email] => [email protected]
)
[1] => Array
(
[name] => Jack Sparrow
[email] => [email protected]
)
[2] => Array
(
[name] => Barack Obama
[email] => [email protected]
)
)
)
'foreachの($ EVENT_ID => $イベントとして$イベントを){ $イベント=新しいイベント();' - あなたがオブジェクトで配列を上書きするところです。 – Niko
Nikoが正しいです。変数をオブジェクトと配列の両方として使用すると、常にエラー(ArrayAccessインタフェース)につながるわけではありません。 OPが変数を上書きしているのは事実です。 – webbiedave
明確にするために引用を修正しました – marfis