Riho
Riho

Reputation: 4593

How to check if the nested property exists in SimpleXML

I would like to get rid of "Trying to get property of non-object" warnings, but couldn't figure out the correct syntax for checking the existance of properties in my case.

$this->nonce = $syncbod->Status->Chal->Meta->NextNonce;

Trying to call

property_exists($syncbod, "Status->Chal")

returns always false. What would be the correct way to check if Chal exists?

Upvotes: 6

Views: 2962

Answers (1)

MKroeders
MKroeders

Reputation: 7752

You should look at isset

See this question, although the question applies to arrays, the same principal applies to the SimpleXml properties. The question was more of a reference to the nested part then the array part

Upvotes: 4

Related Questions