Quote from: splittingred at Feb 26, 2009, 04:53 AM
I would always recommend using $obj->get(’field’) rather than $obj->field, for this reason:
If for some reason down the line we decide to rename the column ’field’ to something else, ->field would not work. However, we could make ->get(’field’) work using internal aliases and logic, making it point to the new name.
In addition, many objects implement very specific logic in the get method for specific fields, so the raw value of the field may not be the same as the value retrieved with get(). In fact, this is the case with all of the timestamp fields represented in modResource, as well as many of the others.
So, yes, you should always use the the get() (and set()) method to access the fields. But if you understand how the raw value is stored vs. how the get() method processes it, it sometimes does make sense to access them directly, though I should have specified only when you know the consequences and otherwise have a good reason to. This will be more important information for Core Extension developers, and I agree with BobRay that direct field access should be hidden from general usage examples in Snippets and Plugins.
Quote from: BobRay at Feb 26, 2009, 04:39 AM
What about implementing the get() method now? Maybe I could skip documentObject altogether.
get() is implemented; this is the xPDOObject->get() method that all objects in the Revolution API have available.
Quote from: BobRay at Feb 26, 2009, 04:39 AM
since it would be easier to use get() all the time than to remember which fields you could get directly.
It also doesn’t cause PHP errors when you try to access non-existent fields using the get() method, like it does if you try to access an object var that does not exist.