This error occured for me when using a View to show a GeoField using the basic GeoField Map with an entity that was programmatically created to be bare bones. The error is in line 277 of entity/includes/entity.inc (also 277 of rc5, and 267 of rc3):

PHP Fatal error: Cannot access empty property in /var/www/html/d.dev/modules/entity/includes/entity.inc on line 267
I am certain that it can be avoided by a more robust set of configuration directives, however, I also think that the EntityAPI code could intercept this type of error, and perhaps should. In short, I think that perhaps this bug has two roots:

It is the result of an improperly or incompletely configured Entity (NOT a problem with EntityAPI module)
Failure to check if a property_exists before trying to access object property in
My proposed fix is below, but I wanted to get feedback on whether or not it is preferable to allow a "fatal error" because of assumptions that the module makes, or to allow "sloppy coding" of entities.

// Change
// return $this->$property;
// TO:
if (property_exists($this, $property)) {
return $this->$property;
} else {
drupal_set_message(t("Property $property does not exist on Entity of class " . get_class($this)), 'error');
return FALSE;
}

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

robertwb’s picture

FileSize
537 bytes

Patch attached.

robertwb’s picture

Version: 7.x-1.0-rc3 » 7.x-1.x-dev
oliverpolden’s picture

Issue summary: View changes
FileSize
762 bytes

This is a patch to reflect the current state of the module and introduces the variable by reference.

oliverpolden’s picture

Issue summary: View changes
robertwb’s picture

@oliverpolden - thanks for the patch on this. Is this triggered because of sloppy coding on my part or is there a legit bug here?

oliverpolden’s picture

This has been fixed in the current release however I am currently stuck on a particular version of this module that doesn't include this fix.

diego21’s picture

Status: Active » Needs review

I change the status because @oliverpolden said that current release fixed this issue. Maybe the issue should be closed.

Thanks.

Status: Needs review » Needs work

The last submitted patch, 3: entity-call_by_reference-2295955-3.patch, failed testing.

mexicoder’s picture

Patch supplied in #3 was not applying correctly against 7.x-1.0 . This should work.