summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2015-04-25 13:18:13 +0200
committerNikita Popov <nikic@php.net>2015-04-25 16:13:39 +0200
commite0a39eecf1d176162783af37c8d2f687c6815059 (patch)
treeb9a38f3bddd69e7f9343326cfd9d52bde5e3bcdd
parent66ce7cc0835a1c0f466b3601427133a0714548af (diff)
downloadphp-git-e0a39eecf1d176162783af37c8d2f687c6815059.tar.gz
Respect USE_OTHER in spl_array_is_object
Also a bit of code cleanup in get_hash_table.
-rw-r--r--ext/spl/spl_array.c19
-rw-r--r--ext/spl/tests/array_028.phpt27
2 files changed, 35 insertions, 11 deletions
diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c
index 4f5f3c921a..c56e2d5f22 100644
--- a/ext/spl/spl_array.c
+++ b/ext/spl/spl_array.c
@@ -83,19 +83,16 @@ static inline spl_array_object *spl_array_from_obj(zend_object *obj) /* {{{ */ {
#define Z_SPLARRAY_P(zv) spl_array_from_obj(Z_OBJ_P((zv)))
static inline HashTable *spl_array_get_hash_table(spl_array_object* intern, int check_std_props) { /* {{{ */
- if ((intern->ar_flags & SPL_ARRAY_IS_SELF) != 0) {
+ if (intern->ar_flags & SPL_ARRAY_IS_SELF
+ || (check_std_props && (intern->ar_flags & SPL_ARRAY_STD_PROP_LIST))
+ ) {
if (!intern->std.properties) {
rebuild_object_properties(&intern->std);
}
return intern->std.properties;
- } else if ((intern->ar_flags & SPL_ARRAY_USE_OTHER) && (check_std_props == 0 || (intern->ar_flags & SPL_ARRAY_STD_PROP_LIST) == 0)) {
+ } else if (intern->ar_flags & SPL_ARRAY_USE_OTHER) {
spl_array_object *other = Z_SPLARRAY_P(&intern->array);
return spl_array_get_hash_table(other, check_std_props);
- } else if ((intern->ar_flags & ((check_std_props ? SPL_ARRAY_STD_PROP_LIST : 0) | SPL_ARRAY_IS_SELF)) != 0) {
- if (!intern->std.properties) {
- rebuild_object_properties(&intern->std);
- }
- return intern->std.properties;
} else {
return HASH_OF(&intern->array);
}
@@ -103,7 +100,9 @@ static inline HashTable *spl_array_get_hash_table(spl_array_object* intern, int
static inline zend_bool spl_array_is_object(spl_array_object *intern) /* {{{ */
{
- //??? shouldn't this take USE_OTHER into account?
+ while (intern->ar_flags & SPL_ARRAY_USE_OTHER) {
+ intern = Z_SPLARRAY_P(&intern->array);
+ }
return (intern->ar_flags & SPL_ARRAY_IS_SELF) || Z_TYPE(intern->array) == IS_OBJECT;
}
/* }}} */
@@ -1278,8 +1277,6 @@ SPL_METHOD(Array, getIterator)
}
ZVAL_OBJ(return_value, spl_array_object_new_ex(intern->ce_get_iterator, object, 0));
- Z_SET_REFCOUNT_P(return_value, 1);
- //!!!PZ_SET_ISREF_P(return_value);
}
/* }}} */
@@ -1628,7 +1625,7 @@ SPL_METHOD(Array, getChildren)
}
}
- ZVAL_LONG(&flags, SPL_ARRAY_USE_OTHER | intern->ar_flags);
+ ZVAL_LONG(&flags, intern->ar_flags);
spl_instantiate_arg_ex2(Z_OBJCE_P(getThis()), return_value, entry, &flags);
}
/* }}} */
diff --git a/ext/spl/tests/array_028.phpt b/ext/spl/tests/array_028.phpt
new file mode 100644
index 0000000000..1adcdd3f90
--- /dev/null
+++ b/ext/spl/tests/array_028.phpt
@@ -0,0 +1,27 @@
+--TEST--
+ArrayObject/Iterator on array with NUL bytes
+--FILE--
+<?php
+$array = [
+ "\0foo" => "bar",
+];
+
+$it = new ArrayIterator($array);
+foreach ($it as $v) {
+ var_dump($v);
+}
+
+$obj = new ArrayObject($array);
+foreach ($obj as $v) {
+ var_dump($v);
+}
+
+$obj = new ArrayObject($it);
+foreach ($obj as $v) {
+ var_dump($v);
+}
+?>
+--EXPECT--
+string(3) "bar"
+string(3) "bar"
+string(3) "bar"