我正在使用该软件包:https://packagist.org/packages/gavroche/ups-api
当我运行时,我从Laravels异常处理程序中得到一些奇怪的行为:
$tracking = new \UPS\Tracking(
'KEY', 'USERNAME', 'PASS'
);
$shipment = $tracking->track('TRACKING NUMBER HERE');
foreach($shipment->Package->Activity as $activity) {
var_dump($activity->ActivityLocation->Address->City);
}
有趣的是,城市是var_dumped但是laravels异常处理程序,在同一口气中,说Undefined属性:stdClass :: $ City。
以下是$活动对象之一的vardump:
object(stdClass)[518]
public 'ActivityLocation' =>
object(stdClass)[519]
public 'Address' =>
object(stdClass)[520]
public 'City' => string 'CLEVELAND' (length=9)
public 'StateProvinceCode' => string 'TN' (length=2)
public 'PostalCode' => string '37311' (length=5)
public 'CountryCode' => string 'US' (length=2)
public 'Code' => string 'M4' (length=2)
public 'Description' => string 'RECEPTION' (length=9)
public 'SignedForByName' => string 'HICKMAN' (length=7)
public 'Status' =>
object(stdClass)[521]
public 'StatusType' =>
object(stdClass)[522]
public 'Code' => string 'D' (length=1)
public 'Description' => string 'DELIVERED' (length=9)
public 'StatusCode' =>
object(stdClass)[523]
public 'Code' => string 'KB' (length=2)
public 'Date' => string '20130426' (length=8)
public 'Time' => string '085500' (length=6)
$ activity-> ActivityLocation->地址对象laravel中的任何属性都会出现问题。但是,我可以请求$ activity-> Status-> StatusType->说明并且没有问题。
常规for循环修复了该问题。似乎是增加php的foreach()的一些问题。
for ($i=0; $i < (count($shipment->Package->Activity) - 1); $i++) {
var_dump($shipment->Package->Activity[$i]->ActivityLocation->Address->City);
}
答案 0 :(得分:0)
您对此并不清楚,但是您是否尝试以
方式访问此内容$activity->ActivityLocation->Address->City ?
您离开问题的$activity
部分并使用$City
而不是City
,我不确定这是否是故意的