summaryrefslogtreecommitdiff
path: root/src/value.cpp
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-10 10:39:22 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-10 10:39:22 +0100
commitd2e10c764d1b8860dd798eda3055fc957ff556ad (patch)
tree10e6d19cdc71f27e08e0134ad30fe34cd05b7046 /src/value.cpp
parent49d88d98a0656233f15923d31ea67a1ed229e514 (diff)
fixed iterators for php 5.3 + updated documentation about iterators
Diffstat (limited to 'src/value.cpp')
-rw-r--r--src/value.cpp79
1 files changed, 55 insertions, 24 deletions
diff --git a/src/value.cpp b/src/value.cpp
index f8ee3e9..a78c2d4 100644
--- a/src/value.cpp
+++ b/src/value.cpp
@@ -1479,25 +1479,43 @@ std::map<std::string,Php::Value> Value::mapValue() const
// reset iterator to beginning of the hash table
zend_hash_internal_pointer_reset(arr);
- // pointer that will be set to hash key and index
- char *key;
- unsigned long ind;
+ // loop through the records
+ while (true)
+ {
+ // pointer that will be set to hash key and index
+ char *key;
+ unsigned long ind;
- // key type
- int hash_key_type;
+ // get current key
+ int hash_key_type = zend_hash_get_current_key(arr, &key, &ind, 0);
- // loop through the recors
- while ((hash_key_type = zend_hash_get_current_key(arr, &key, &ind, 0)) != HASH_KEY_NON_EXISTENT)
- {
// required variable
zval **value;
- // retrieve data
- zend_hash_get_current_data(arr, (void **) &value);
+ // check the type
+ switch (hash_key_type) {
+
+ // was it a string?
+ case HASH_KEY_IS_STRING:
- // check the type of key
- if (HASH_KEY_IS_LONG != hash_key_type) result[key] = Value(*value);
- else result[std::to_string(ind)] = Value(*value);
+ // retrieve data, and add to result
+ zend_hash_get_current_data(arr, (void **) &value);
+ result[key] = Value(*value);
+ break;
+
+ // was it numeric?
+ case HASH_KEY_IS_LONG:
+
+ // retrieve data, and add to result
+ zend_hash_get_current_data(arr, (void **) &value);
+ result[std::to_string(ind)] = Value(*value);
+ break;
+
+ default:
+
+ // we're ready
+ return result;
+ }
// next iteration
zend_hash_move_forward(arr);
@@ -1511,24 +1529,37 @@ std::map<std::string,Php::Value> Value::mapValue() const
// reset iterator to beginning of the hash table
zend_hash_internal_pointer_reset(arr);
- // pointer that will be set to hash key and index
- char *key;
- unsigned long ind;
-
// loop through the records
- while( zend_hash_get_current_key(arr, &key, &ind, 0) != HASH_KEY_NON_EXISTENT )
+ while (true)
{
- // if property is accessible (i.e. propertie access type is public. See rebuild_object_properties )
- if('\0' != *key)
- {
+ // pointer that will be set to hash key and index
+ char *key;
+ unsigned long ind;
+
+ // get current key
+ int hash_key_type = zend_hash_get_current_key(arr, &key, &ind, 0);
+
+ // check the type
+ switch (hash_key_type) {
+
+ // was it a string?
+ case HASH_KEY_IS_STRING:
+
+ // inaccessible properties (privates) start with a null character
+ if (*key == '\0') break;
+
// required variable
zval **value;
- // retrieve property
+ // retrieve data, and add to result
zend_hash_get_current_data(arr, (void **) &value);
-
- // append to mape
result[key] = Value(*value);
+ break;
+
+ default:
+
+ // we're ready
+ return result;
}
// next iteration