Source: blog.cotten.io

PHP Bugs: Property Problems

Category: PHP, PHP, api, api

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
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners