PHP doesn’t mind very much if you try to access a missing property (member variable) from an object. It just throws you an E_NOTICE and returns NULL, confident that your logic will properly handle its falsey nature.
In this example you see that isset() and property_exists() act in nearly the same way, except for the final test case with $bird->tail->type in that it is set as a property but contains a NULL value: Since we’re going to operate on two additional sub-properties of TrackDetails it’s important for us to know that it’s not NULL, making isset() more attractive.
Again, an IDE might point this out to you, but keep in mind that PHP allows you to dynamically set new properties at runtime, so it’s quite possible that it wouldn’t have been flagged.
Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox.Explore