Magic accessors
Last updated not available | Page history | Improve this page | Report an issue
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$194 per month—let's make that $500!
Learn morexPDOObject magic accessors¶
xPDOObject implements the magic methods __get(), __set() and __isset() so that fields and loaded related objects can be accessed as properties.
These accessors are only active when the corresponding hydration options are enabled:
-
xPDO::OPT_HYDRATE_FIELDS— exposes fields as readable properties via__get(). -
xPDO::OPT_HYDRATE_RELATED_OBJECTS— exposes loaded related objects as readable properties via__get(). -
xPDO::OPT_HYDRATE_ADHOC_FIELDS— exposes ad-hoc (not declared) fields.
When the options are disabled, __get() silently returns null and __set() returns false, so accessing $object->somefield appears to work but yields nothing.
Syntax¶
mixed __get (string $name)
boolean __set (string $name, mixed $value)
boolean __isset (string $name)
Example¶
$modx->setOption(xPDO::OPT_HYDRATE_FIELDS, true);
$resource = $modx->getObject('modResource', 42);
echo $resource->pagetitle;
See Also¶
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$194 per month—let's make that $500!
Learn more










