I make a lot of SOAP calls to external services in PHP, and sometimes the XML I get back provides a field, sometimes it provides that field, but empty, and sometimes it just doesn't provide it at all. So every time I want to store a value, I have to wrap it like so:
$age = (isset($person['age']) && !empty($person['age'])) ? $person['age'] : NULL;
I thought I could simply make a function to do that, or call empty()
alone, but as soon as I do that without the isset
check first, I get a call to an undefined index when the XML I get back lacks the age
index.
Is there a shorthand way of checking BOTH isset
and empty
? Or some function I can build myself which won't result in this warning (but still will give me any others, in case there are REAL problems)?