Silent Failure with the WOOF_Silent class
One of the nicest aspects of coding with the MasterPress API is the way it allows developers to drill down into nested object properties via chained property access and method calls. Frequently, you can access these nested properties and methods using just a single line of code:
Example 1: Resizing a photo field in a details field set, via nested property and method access
If you’re familiar with writing object-oriented code, however, the example above may beg the question: “What happens when either of the “about-us” page, the details field set or the photo field don’t exist – will the code fail with an error in the middle somewhere?”
MasterPress handles these scenarios with a special WOOF_Silent class, which is used throughout the API to represent “doesn’t exist”, “empty”,”false”, or some other error condition. WOOF_Silent is essentially like a vacuum – it swallows up most attempts to call methods on it, access properties of it, iterate over it, or attempts to echo it, causing them to essentially “do nothing“.
Importantly, methods throughout the API are written to return a WOOF_Silent object when something isn’t found, with a descriptive error about why it wasn’t found, rather than returning false or null. Consider a pseudocode outline of the “page” method above: