tags:

views:

973

answers:

2

A->b->c might exist but c might not exist. How do i check it?

+1  A: 
if($A->b->c != null) //c exists

if C does not exists it's value will be null (or more precise, it will have no value) note however that for this to work both A and b need to not be null (otherwise php will throw an error (I think, not quite sure))

Pim Jager
+3  A: 

It might be better to wrap this in an isset()

if(isset($A->b->c)) { // c exists

That way if $A or $A->b don't exist... it doesn't blow up.

null