summaryrefslogtreecommitdiff
path: root/zend/value.cpp
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-09 10:08:29 +0200
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-09 10:08:29 +0200
commit3953d8833e070fa1d6cc7b264dd19ed56c909f02 (patch)
treeb57091d0bfc1dd6234be9d09b6ba55e77948c8e4 /zend/value.cpp
parent614d95ad69f4e1d3457f2831abc94ecb0809c12e (diff)
added support for accessing array keys by other value objects, support for unsetting array members, support for array_key_exists(), isset() and unset() functions (feature request in from issue #71)
Diffstat (limited to 'zend/value.cpp')
-rw-r--r--zend/value.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/zend/value.cpp b/zend/value.cpp
index 2ca1585..a8fadce 100644
--- a/zend/value.cpp
+++ b/zend/value.cpp
@@ -1841,6 +1841,51 @@ void Value::set(const char *key, int size, const Value &value)
}
/**
+ * Unset a member by its index
+ * @param index
+ */
+void Value::unset(int index)
+{
+ // only necessary for arrays
+ if (!isArray()) return;
+
+ // if this is not a reference variable, we should detach it to implement copy on write
+ SEPARATE_ZVAL_IF_NOT_REF(&_val);
+
+ // remove the index
+ zend_hash_index_del(Z_ARRVAL_P(_val), index);
+}
+
+/**
+ * Unset by key name and length of the key
+ * @param key
+ * @param size
+ */
+void Value::unset(const char *key, int size)
+{
+ // is this an object?
+ if (isObject())
+ {
+ // if this is not a reference variable, we should detach it to implement copy on write
+ SEPARATE_ZVAL_IF_NOT_REF(&_val);
+
+ // we need the tsrm_ls variable
+ TSRMLS_FETCH();
+
+ // in the zend header files, unsetting properties is redirected to setting it to null...
+ add_property_null_ex(_val, key, size TSRMLS_CC);
+ }
+ else if (isArray())
+ {
+ // if this is not a reference variable, we should detach it to implement copy on write
+ SEPARATE_ZVAL_IF_NOT_REF(&_val);
+
+ // remove the index
+ zend_hash_del(Z_ARRVAL_P(_val), key, size);
+ }
+}
+
+/**
* Array access operator
* This can be used for accessing arrays
* @param index
@@ -1852,6 +1897,16 @@ HashMember<int> Value::operator[](int index)
}
/**
+ * Index by other value object
+ * @param key
+ * @return HashMember<std::string>
+ */
+HashMember<Value> Value::operator[](const Value &key)
+{
+ return HashMember<Value>(this, key);
+}
+
+/**
* Array access operato
* This can be used for accessing associative arrays
* @param key