summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rw-r--r--Zend/tests/bug73998.phpt19
-rw-r--r--Zend/zend_builtin_functions.c16
-rw-r--r--Zend/zend_hash.h10
4 files changed, 45 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index 5bd07e040f..e1f33e73b7 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,8 @@ PHP NEWS
- Core:
. Fixed bug #73807 (Performance problem with processing large post request).
(Nikita)
+ . Fixed bug #73998 (array_key_exists fails on arrays created by
+ get_object_vars). (mhagstrand)
- GD:
. Fixed bug #74031 (ReflectionFunction for imagepng is missing last two
diff --git a/Zend/tests/bug73998.phpt b/Zend/tests/bug73998.phpt
new file mode 100644
index 0000000000..41813269d1
--- /dev/null
+++ b/Zend/tests/bug73998.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Bug #73998 (array_key_exists fails on arrays created by get_object_vars)
+--DESCRIPTION--
+Properties of objects with numeric names should be accessible
+--FILE--
+<?php
+$a = new stdClass;
+$a->{1234} = "Numeric";
+$a->a1234 = "String";
+
+$properties = get_object_vars($a);
+var_dump(array_key_exists(1234, $properties));
+echo "Value: {$properties[1234]}\n";
+
+?>
+--EXPECT--
+bool(true)
+Value: Numeric
+
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index 6f333cb041..12f9f29636 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -1223,6 +1223,8 @@ ZEND_FUNCTION(get_object_vars)
HashTable *properties;
zend_string *key;
zend_object *zobj;
+ zend_ulong index;
+ zend_bool fast_copy = 0;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_OBJECT(obj)
@@ -1241,7 +1243,17 @@ ZEND_FUNCTION(get_object_vars)
zobj = Z_OBJ_P(obj);
if (!zobj->ce->default_properties_count && properties == zobj->properties && !ZEND_HASH_GET_APPLY_COUNT(properties)) {
- /* fast copy */
+ fast_copy = 1;
+ /* Check if the object has a numeric property, See Bug 73998 */
+ ZEND_HASH_FOREACH_STR_KEY(properties, key) {
+ if (key && ZEND_HANDLE_NUMERIC(key, index)) {
+ fast_copy = 0;
+ break;
+ }
+ } ZEND_HASH_FOREACH_END();
+ }
+
+ if (fast_copy) {
if (EXPECTED(zobj->handlers == &std_object_handlers)) {
if (EXPECTED(!(GC_FLAGS(properties) & IS_ARRAY_IMMUTABLE))) {
GC_REFCOUNT(properties)++;
@@ -1267,7 +1279,7 @@ ZEND_FUNCTION(get_object_vars)
zend_unmangle_property_name_ex(key, &class_name, &prop_name, &prop_len);
zend_hash_str_add_new(Z_ARRVAL_P(return_value), prop_name, prop_len, value);
} else {
- zend_hash_add_new(Z_ARRVAL_P(return_value), key, value);
+ zend_symbtable_add_new(Z_ARRVAL_P(return_value), key, value);
}
}
}
diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h
index 2e41459322..1b998085e9 100644
--- a/Zend/zend_hash.h
+++ b/Zend/zend_hash.h
@@ -337,6 +337,16 @@ static zend_always_inline int zend_hash_str_exists_ind(const HashTable *ht, cons
Z_TYPE_P(Z_INDIRECT_P(zv)) != IS_UNDEF);
}
+static zend_always_inline zval *zend_symbtable_add_new(HashTable *ht, zend_string *key, zval *pData)
+{
+ zend_ulong idx;
+
+ if (ZEND_HANDLE_NUMERIC(key, idx)) {
+ return zend_hash_index_add_new(ht, idx, pData);
+ } else {
+ return zend_hash_add_new(ht, key, pData);
+ }
+}
static zend_always_inline zval *zend_symtable_update(HashTable *ht, zend_string *key, zval *pData)
{