When i try to save an entity, the save() method return NULL.

I've seen that the properties of the Entity class are dynamically defined in entity.db.inc l.40:

// Set initial values.
    foreach ($values as $key => $value) {
      $this->$key = $value;
    }

But drupal_write_record() use the function property_exists() which check each property of the entity in includes/common.inc l.6684:

if (!property_exists($object, $field)) {
      // Skip fields that are not provided, default values are already known
      // by the database.
      continue;
    }

All the properties of my entity are skipped because they are dynamically defined.

On php.net you can read that note about property_exists:


"The property_exists() function cannot detect properties that are magically accessible using the __get magic method."

Comments

fago’s picture

Title: Saving an entity doesn't work » Support magic properties
Status: Active » Closed (won't fix)

Yep, the entity API doesn't support magic properties, just by the fact drupal_write_record() doesn't support them. So not really a problem of the entity API, but of that function. However, I'd not suggest using magic properties for something like entity properties anyway.