aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/entities.php
diff options
context:
space:
mode:
authoricewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-25 15:57:58 +0000
committericewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-25 15:57:58 +0000
commit67ec78157631f4d2eb9d737b5c689fd51b735880 (patch)
tree1cf5c28c8a2f79660a44bc7008eda661b79ee007 /engine/lib/entities.php
parent751d363785f14718cd0d396b16a8d8656f5ea31e (diff)
downloadelgg-67ec78157631f4d2eb9d737b5c689fd51b735880.tar.gz
elgg-67ec78157631f4d2eb9d737b5c689fd51b735880.tar.bz2
Marcus Povey <marcus@dushka.co.uk>
* Objects can be accessed as arrays git-svn-id: https://code.elgg.org/elgg/trunk@535 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/entities.php')
-rw-r--r--engine/lib/entities.php34
1 files changed, 33 insertions, 1 deletions
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index 3e912836a..21ef3d595 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -22,7 +22,8 @@
abstract class ElggEntity implements
Exportable, // Allow export of data
Importable, // Allow import of data
- Iterator // Override foreach behaviour
+ Iterator, // Override foreach behaviour
+ ArrayAccess // Override for array access
{
/**
* The main attributes of an entity.
@@ -511,6 +512,37 @@
return $this->valid;
}
+ // ARRAY ACCESS INTERFACE //////////////////////////////////////////////////////////
+ /*
+ * This lets an entity's attributes be accessed like an associative array.
+ * Example: http://www.sitepoint.com/print/php5-standard-library
+ */
+
+ function offsetSet($key, $value)
+ {
+ if ( array_key_exists($key, $this->attributes) ) {
+ $this->attributes[$key] = $value;
+ }
+ }
+
+ function offsetGet($key)
+ {
+ if ( array_key_exists($key, $this->attributes) ) {
+ return $this->attributes[$key];
+ }
+ }
+
+ function offsetUnset($key)
+ {
+ if ( array_key_exists($key, $this->attributes) ) {
+ $this->attributes[$key] = ""; // Full unsetting is dangerious for our objects
+ }
+ }
+
+ function offsetExists($offset)
+ {
+ return array_key_exists($offset, $this->attributes);
+ }
}
/**