[Solar-svn] Revision 2758

pmjones at solarphp.com pmjones at solarphp.com
Tue Sep 18 20:30:25 CDT 2007


branch: Solar_Struct

* [CHG] Method offsetUnset() now actually unsets the element, instead of setting it to null.

* [CHG] Method load() no longer uses array_merge() internally, and instead calls __set() on each data element using a loop.  This lets extended classes intercept the assignment.




Modified: branches/orm/Solar/Struct.php
===================================================================
--- branches/orm/Solar/Struct.php	2007-09-19 01:25:21 UTC (rev 2757)
+++ branches/orm/Solar/Struct.php	2007-09-19 01:30:25 UTC (rev 2758)
@@ -231,8 +231,19 @@
             $data = array();
         }
         
-        // load new data, merging new values with old
-        $this->_data = array_merge($this->_data, $data);
+        // because we may have overrides in subclasses, it's not enough
+        // to just merge the data.  although slower, we need to loop and
+        // do assigns with some extra processing so that __set() is honored.
+        foreach ($data as $key => $val) {
+            $chr = substr($key, 0, 1);
+            if (ctype_alpha($chr) || $chr == '_') {
+                // valid variable name, use magic __set() on it.
+                $this->$key = $val;
+            } else {
+                // not a valid variable name, set directly in $_data.
+                $this->_data[$key] = $val;
+            }
+        }
     }
     
     /**
@@ -281,7 +292,7 @@
     
     /**
      * 
-     * ArrayAccess: unset a key (sets it to null).
+     * ArrayAccess: unset a key.
      * 
      * @param string $key The requested key.
      * 
@@ -290,7 +301,8 @@
      */
     public function offsetUnset($key)
     {
-        $this->__set($key, null);
+        $this->_data[$key] = null;
+        unset($this->_data[$key]);
     }
     
     /**




More information about the Solar-svn mailing list