Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if the nested property exists in SimpleXML

Tags:

php

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?

like image 545
Riho Avatar asked Oct 22 '22 12:10

Riho


1 Answers

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

like image 69
MKroeders Avatar answered Oct 24 '22 03:10

MKroeders