davidtsadler / ebay-sdk-php

An eBay SDK for PHP. Use the eBay API in your PHP projects.
Apache License 2.0
350 stars 343 forks source link

BaseType->__isset should not throw an exception #57

Closed jhalterman closed 7 years ago

jhalterman commented 7 years ago

I'm having trouble checking whether a property exists on a response since BaseType->__isset throws an exception if the property does not exist. Shouldn't this just return boolean?

One place where this comes up is checking for the presence of optional properties, such as isset($response->PaginationResult). Current workaround is property_exists($response, 'PaginationResult').

davidtsadler commented 7 years ago

Can I see some example code where this is failing? The intended behaviour of __isset is that it should throw an exception if a property is not a member of the class. This is the same behaviour as getting or setting a property. http://devbay.net/sdk/guides/guide/request-and-response-objects.html#property-names-must-exist

For example:

$response = $findingService->findItemsAdvanced($request);
// Won't throw as paginationOutput is a member of the FindItemsAdvancedResponse class.
// It will return a boolean to indicate if the property was set.
if (isset($response->paginationOutput)) {
  echo $response->paginationOutput->paginationOutput->totalEntries;
}

// Will throw as PaginationResult is not a member.
if (isset($response->PaginationResult)) {
}
jhalterman commented 7 years ago

@davidtsadler Good call. The request/response I'm working with in this case is GetMyMessagesRequestType and GetMyMessagesResponseType. Oddly, GetMyMessagesRequestType has a Pagination property but on closer inspection GetMyMessagesResponseType does not appear to contain PaginationOutput or a PaginationResult which would explain the exception. As an aside - do you know why this is, that a request would seem to support pagination but the response does not mention it?

davidtsadler commented 7 years ago

I've never used GetMyMessages but I agree that it does seem strange that there is no pagination in the results. I don't know if it's a bug or intentional to be honest.