[Solar-svn] Revision 2830

pmjones at solarphp.com pmjones at solarphp.com
Sat Oct 6 10:59:39 CDT 2007


Solar_Struct
------------

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

* [CHG] "Unified" internals so that ArrayAccess and Iterator methods call __get(), __set(), __isset(), and __unset().




Modified: trunk/Solar/Struct.php
===================================================================
--- trunk/Solar/Struct.php	2007-10-06 15:58:15 UTC (rev 2829)
+++ trunk/Solar/Struct.php	2007-10-06 15:59:39 UTC (rev 2830)
@@ -93,7 +93,7 @@
      * 
      * `data`
      * : (array) Key-value pairs.
-     *
+     * 
      * @var array
      * 
      */
@@ -147,9 +147,7 @@
      */
     public function __get($key)
     {
-        if (array_key_exists($key, $this->_data)) {
-            return $this->_data[$key];
-        }
+        return $this->_data[$key];
     }
     
     /**
@@ -172,6 +170,9 @@
      * 
      * Does a certain key exist in the data?
      * 
+     * Note that this is slightly different from normal PHP isset(); it will
+     * say the key is set, even if the key value is null or otherwise empty.
+     * 
      * @param string $key The requested data key.
      * 
      * @param mixed $val The value to set the data to.
@@ -195,6 +196,7 @@
      */
     public function __unset($key)
     {
+        $this->_data[$key] = null;
         unset($this->_data[$key]);
     }
     
@@ -246,7 +248,7 @@
      */
     public function offsetExists($key)
     {
-        return array_key_exists($key, $this->_data);
+        return $this->__isset($key);
     }
     
     /**
@@ -281,7 +283,7 @@
     
     /**
      * 
-     * ArrayAccess: unset a key (sets it to null).
+     * ArrayAccess: unset a key.
      * 
      * @param string $key The requested key.
      * 
@@ -290,7 +292,7 @@
      */
     public function offsetUnset($key)
     {
-        $this->__set($key, null);
+        $this->__unset($key);
     }
     
     /**
@@ -307,19 +309,19 @@
     
     /**
      * 
-     * Iterator: get the current key value.
+     * Iterator: get the current value for the array pointer.
      * 
      * @return mixed
      * 
      */
     public function current()
     {
-        return current($this->_data);
+        return $this->__get($this->key());
     }
-
+    
     /**
      * 
-     * Iterator: what is the key at the current position?
+     * Iterator: get the current key for the array pointer.
      * 
      * @return mixed
      * 
@@ -328,7 +330,7 @@
     {
         return key($this->_data);
     }
-
+    
     /**
      * 
      * Iterator: move to the next position.
@@ -340,7 +342,7 @@
     {
         $this->_iterator_valid = (next($this->_data) !== false);
     }
-
+    
     /**
      * 
      * Iterator: move to the first position.
@@ -352,7 +354,7 @@
     {
         $this->_iterator_valid = (reset($this->_data) !== false);
     }
-
+    
     /**
      * 
      * Iterator: is the current position valid?




More information about the Solar-svn mailing list