yii2 - PHP: Trying to get property of non-object, from BatchError object of Bing Ads API -
i error when try view error messages api. documentation says returns array of batcherror objects in partialerror field. when try access index property of batcherror, gives me error. wrong?
https://msdn.microsoft.com/en-us/library/bing-ads-campaign-management-addadgroups.aspx#anchor_1
php notice – yii\base\errorexception trying property of non-object 1. in /cygdrive/c/users/chloe/workspace/bestsales/models/bingads.php @ line 384 $response = $campaignproxy->getservice()->addadgroups($request); } catch (\soapfault $e) { $this->handleexception($e); return null; } $adgroupsids = $response->adgroupids; $partialerrors = $response->partialerrors; foreach ($partialerrors $batcherror) { yii::error($batcherror); $adgroup = $adgroups[$batcherror->index]; # <<<<
logs:
2016-09-11 22:15:59 [::1][1][v5adqit0fiae7bon3i1lks49m3][error][application] [ unserialize('o:8:"stdclass":8:{s:4:"code";i:1016;s:7:"details";n;s:9:"errorcode";s:33:"campaignserviceinvalidentitystate";s:9:"fieldpath";n;s:23:"forwardcompatibilitymap";n;s:5:"index";i:0;s:7:"message";s:104:"passed entity state invalid. please refer documentation list of valid values given entity.";s:4:"type";s:10:"batcherror";}'), ] in /cygdrive/c/users/chloe/workspace/bestsales/models/bingads.php:383 in /cygdrive/c/users/chloe/workspace/bestsales/models/adgroup.php:195 in /cygdrive/c/users/chloe/workspace/bestsales/models/keyword.php:145 2016-09-11 22:15:59 [::1][1][v5adqit0fiae7bon3i1lks49m3][error][yii\base\errorexception:8] exception 'yii\base\errorexception' message 'trying property of non-object' in /cygdrive/c/users/chloe/workspace/bestsales/models/bingads.php:384
i tried
yii::error($batcherror); yii::error($batcherror['index']); yii::error($batcherror::$index); yii::error($batcherror->$index); yii::error($batcherror->index);
i used vardumper
, got this:
[ 0 => stdclass#1 ( [code] => 1016 [details] => null [errorcode] => 'campaignserviceinvalidentitystate' [fieldpath] => null [forwardcompatibilitymap] => null [index] => 0 [message] => 'passed entity state invalid. please refer documentation list of valid values given entity.' [type] => 'batcherror' ) ]
i able fix with
$partialerrors = $response->partialerrors; if (!empty($partialerrors->batcherror)) $partialerrors = $partialerrors->batcherror; foreach ($partialerrors $batcherror) {
apparently foreach
able loop on properties of object too, did know know do, , apparently partialerrors
object 1 property named batcherror
then contains array (but batcherror
may not exist @ all). doesn't match documentation, or @ least not documentation of least surprise.
Comments
Post a Comment