Jump to main content Jump to doc navigation

xPDOObject 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

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • CrewMark
  • Fabian Christen
  • Sepia River Studios
  • Dannevang Digital
  • Alex
  • A. Moreno
  • Chris Fickling
  • Stéphane Jäggi
  • Murray Wood
  • Anton Tarasov
  • JT Skaggs
  • deJaya
  • Lefthandmedia
  • eydolan
  • Following Sea
  • Guido Gallenkamp
  • YJ
  • Raffy
  • Snow Creative
  • Nick Clark
  • Guest
  • Helen
  • krisznet
  • Yanni
  • Richard

Budget

$194 per month—let's make that $500!

Learn more