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;
}
Comment | File | Size | Author |
---|---|---|---|
#9 | entity-call_by_reference-2295955-9.patch | 498 bytes | mexicoder |
#3 | entity-call_by_reference-2295955-3.patch | 762 bytes | oliverpolden |
Comments
Comment #1
robertwb CreditAttribution: robertwb commentedPatch attached.
Comment #2
robertwb CreditAttribution: robertwb commentedComment #3
oliverpolden CreditAttribution: oliverpolden commentedThis is a patch to reflect the current state of the module and introduces the variable by reference.
Comment #4
oliverpolden CreditAttribution: oliverpolden commentedComment #5
robertwb CreditAttribution: robertwb commented@oliverpolden - thanks for the patch on this. Is this triggered because of sloppy coding on my part or is there a legit bug here?
Comment #6
oliverpolden CreditAttribution: oliverpolden commentedThis 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.
Comment #7
diego21 CreditAttribution: diego21 commentedI change the status because @oliverpolden said that current release fixed this issue. Maybe the issue should be closed.
Thanks.
Comment #9
mexicoder CreditAttribution: mexicoder commentedPatch supplied in #3 was not applying correctly against 7.x-1.0 . This should work.