summaryrefslogtreecommitdiff
path: root/src/value.cpp
diff options
context:
space:
mode:
authorvalmat <ufabiz@gmail.com>2014-03-09 20:17:20 +0600
committervalmat <ufabiz@gmail.com>2014-03-09 20:17:20 +0600
commit5a186cc932524d85ce602e152a79d5201a4eb3b5 (patch)
tree36088c2bd542e239672cb2a6bb01494c16caf650 /src/value.cpp
parentd76e1c204a1adcaa2a605ed3041a0f1711c716dc (diff)
issue #23: Fixed loop for an objects contains no public properties
Diffstat (limited to 'src/value.cpp')
-rw-r--r--src/value.cpp52
1 files changed, 35 insertions, 17 deletions
diff --git a/src/value.cpp b/src/value.cpp
index 2c44616..d2646f9 100644
--- a/src/value.cpp
+++ b/src/value.cpp
@@ -1425,6 +1425,7 @@ std::map<std::string,Php::Value> Value::mapValue() const
// get access to the internal hash table of _val
// see Zend/zend_API.h 723: HASH_OF(_val)
HashTable *arr = isArray() ? Z_ARRVAL_P(_val) : Z_OBJ_HT_P(_val)->get_properties((_val) TSRMLS_CC);
+
// similarly php: reset($array):
// The definition of this and the following functions can be found in Zend/zend_hash.h 174
@@ -1432,28 +1433,45 @@ std::map<std::string,Php::Value> Value::mapValue() const
// If the following line to remove, then repeated calling the Value::mapValue() will return an empty map
zend_hash_internal_pointer_reset(arr);
- // check empty array/object
- if(zend_hash_has_more_elements(arr) == FAILURE) {
- return result;
+ if (isArray())
+ {
+ unsigned int hash_key_type;
+ while( (hash_key_type = zend_hash_get_current_key(arr, &key, &ind, 0)) != HASH_KEY_NON_EXISTENT )
+ {
+ zend_hash_get_current_data(arr, (void **) &value);
+
+ if(HASH_KEY_IS_LONG == hash_key_type)
+ {
+ result[std::to_string(ind)] = Value(*value);
+ }
+ else // hash_key_type == HASH_KEY_IS_STRING
+ {
+ result[key] = Value(*value);
+ }
+
+ // next iteration
+ zend_hash_move_forward(arr);
+ }
}
-
- unsigned int hash_key_type;
- while( (hash_key_type = zend_hash_get_current_key(arr, &key, &ind, 0)) != HASH_KEY_NON_EXISTENT )
+ else
{
- zend_hash_get_current_data(arr, (void **) &value);
-
- if(HASH_KEY_IS_LONG == hash_key_type)
+ // For obtaining a hashtable of the object meets function void rebuild_object_properties(zend_object *zobj)
+ // Zend/zend_object_handlers.c 66
+ // hashtable of object's properties always has string (no integer) keys
+ while( zend_hash_get_current_key(arr, &key, &ind, 0) != HASH_KEY_NON_EXISTENT )
{
- result[std::to_string(ind)] = Value(*value);
- }
- else // hash_key_type == HASH_KEY_IS_STRING
- {
- result[key] = Value(*value);
+ // if propertie is accessible (i.e. propertie access type is public. See rebuild_object_properties )
+ if('\0' != *key)
+ {
+ zend_hash_get_current_data(arr, (void **) &value);
+ result[key] = Value(*value);
+ }
+
+ // next iteration
+ zend_hash_move_forward(arr);
}
-
- // next iteration
- zend_hash_move_forward(arr);
}
+
}
// done