madsem
1 week ago

Undefined property, but when dumped it exists. How can that happen?

Posted 1 week ago by madsem

I'm working with an external API, when retrieving a response I get an exception that the property is not defined. But it is, and if I dd it, it also displays... How can that even happen? I'm honestly lost how to even begin debugging this.

 ErrorException

  Undefined property: stdClass::$Campaign

This is the code:

$response = $this->client
            ->call($this->client->getCampaignManagementService(), 'GetCampaignsByAccountId', $request)
            ->Campaigns
            ->Campaign;
dump($response);

As you can see I added a dump there, this is the output: (with some redactions)

array:2 [
  0 => {#1176
    +"AudienceAdsBidAdjustment": null
    +"BiddingScheme": {#1171
      +"Type": "EnhancedCpc"
    }
    +"BudgetType": "DailyBudgetStandard"
    +"DailyBudget": xxx
    +"ExperimentId": null
    +"FinalUrlSuffix": null
    +"ForwardCompatibilityMap": {#2136}
    +"Id": xxx
    +"Name": "xxx"
    +"Status": "Paused"
    +"SubType": null
    +"TimeZone": "EasternTimeUSCanada"
    +"TrackingUrlTemplate": null
    +"UrlCustomParameters": null
    +"CampaignType": "Search"
    +"Settings": null
    +"BudgetId": null
    +"Languages": {#1199
      +"string": array:1 [
        0 => "All"
      ]
    }
  }
  1 => {#1911
    +"AudienceAdsBidAdjustment": null
    +"BiddingScheme": {#2066
      +"Type": "EnhancedCpc"
    }
    +"BudgetType": "DailyBudgetStandard"
    +"DailyBudget": xxx
    +"ExperimentId": null
    +"FinalUrlSuffix": null
    +"ForwardCompatibilityMap": {#2129}
    +"Id": xxx
    +"Name": "xxx"
    +"Status": "Paused"
    +"SubType": null
    +"TimeZone": "EasternTimeUSCanada"
    +"TrackingUrlTemplate": null
    +"UrlCustomParameters": null
    +"CampaignType": "Search"
    +"Settings": null
    +"BudgetId": null
    +"Languages": {#2130
      +"string": array:1 [
        0 => "All"
      ]
    }
  }
]

   ErrorException

  Undefined property: stdClass::$Campaign

  at app/Clients/Platforms/Operations/Bing/Get.php:157
    153|          */
    154|         $response = $this->client
    155|             ->call($this->client->getCampaignManagementService(), 'GetCampaignsByAccountId', $request)
    156|             ->Campaigns
  > 157|             ->Campaign;
    158| dump($response);

So it dumps out the actual response object, just as expected, and then errors out that the property is not defined, which it clearly is though...

This is the call method I'm using:

public function call($service, $method, $args = null)
    {
        try {

            $soapClient = $this->service($service)->GetService();

            return $soapClient->{$method}($args);

        } catch (SoapFault $e) {

            throw new ClientException($e->getMessage(), 0, $e);
        }
    }

Anyone got an idea what is going on here? I have never seen anything like it

Please sign in or create an account to participate in this conversation.