We have moved to Github. Please open tickets there.

Opened 3 years ago

Closed 3 years ago

#1414 closed Defect (fixed)

isset() incorrect for metadata

Reported by: twall Owned by:
Priority: high Milestone: Elgg 1.7
Component: Core Version: 1.5
Severity: major Keywords: metadata isset
Cc: brettp Difficulty:

Description

Assigning a value of zero to an object field results in the field reported as "unset". This is true whether the field persistence is backed by metadata (objects/entities) or private settings (widgets).

$obj->metadata = 1;
assertTrue(isset($obj->metadata));

$obj->metadata = 0;
assertTrue(isset($obj->metadata));

unset($obj->metadata);
assertFalse(isset($obj->metadata));

Change History (9)

comment:1 Changed 3 years ago by brettp

  • Priority changed from major to minor

The same is true of $obj->metadata = ; Will need to create a few helper functions like metadata/private_setting_exists($guid, $md_name) to check if that metadata is registered against that entity as a name_id.

comment:2 Changed 3 years ago by brettp

  • Priority changed from minor to major

It's occurred to me the OP is probably having problems checking widget settings where a possible option is 0. Setting this back to "major."

comment:3 Changed 3 years ago by twall

Yes, that is *exactly* what I was having problems with. An integer position, when it has value zero, shows up as "unset".

comment:4 Changed 3 years ago by cash

Why not implement isset()?

comment:5 Changed 3 years ago by cash

Grrr... that should be

__isset()

comment:6 Changed 3 years ago by brettp

isset() is implement, only poorly. We need to see if the metadata exists at all for the entity, regardless of its value. The current isset() returns metadata value != . We could make a simple exemption for ints, though...

comment:7 Changed 3 years ago by cash

Oh, I see. I missed that.

Change the code to:

return $this->$name !== NULL;

That should work.

comment:8 Changed 3 years ago by brettp

Indeed it does...I didn't realize the metadata fetching functions were that fleshed out. Definitely the simplest solution ;)

comment:9 Changed 3 years ago by brettp

  • Resolution set to fixed
  • Status changed from new to closed

(In [svn:3803]) Fixes #1414: Metadata set to a falsy value (except NULL) returns TRUE for isset($obj->md).

Note: See TracTickets for help on using tickets.