summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2018-10-11 16:08:58 +0200
committerNikita Popov <nikita.ppv@gmail.com>2018-10-11 16:10:22 +0200
commit0b6063f33112b4685bc3c23ae823556fec8f32f1 (patch)
treecf35a4f93966b1c65b250914f436f5bc57a99694 /ext
parentda4867195965c2b6e9a04037e1edd40967463db2 (diff)
downloadphp-git-0b6063f33112b4685bc3c23ae823556fec8f32f1.tar.gz
Restore array_key_exists() compatibility for ArrayObject
Doing this by special-casing array_key_exists() for ArrayObject.
Diffstat (limited to 'ext')
-rw-r--r--ext/spl/spl_array.c1
-rw-r--r--ext/spl/tests/bug61347.phpt4
-rw-r--r--ext/standard/array.c38
3 files changed, 24 insertions, 19 deletions
diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c
index 9d7a51af8e..04e73bf26e 100644
--- a/ext/spl/spl_array.c
+++ b/ext/spl/spl_array.c
@@ -805,6 +805,7 @@ static HashTable *spl_array_get_properties_for(zval *object, zend_prop_purpose p
break;
case ZEND_PROP_PURPOSE_VAR_EXPORT:
case ZEND_PROP_PURPOSE_JSON:
+ case _ZEND_PROP_PURPOSE_ARRAY_KEY_EXISTS:
dup = 0;
break;
default:
diff --git a/ext/spl/tests/bug61347.phpt b/ext/spl/tests/bug61347.phpt
index 720cf5b0f2..cb091858ae 100644
--- a/ext/spl/tests/bug61347.phpt
+++ b/ext/spl/tests/bug61347.phpt
@@ -12,7 +12,7 @@ var_dump(isset($b['no_exists'])); //false
var_dump(empty($b['b'])); //true
var_dump(empty($b[37])); //true
-var_dump(array_key_exists('b', $b)); //false
+var_dump(array_key_exists('b', $b)); //true
var_dump($b['b']);
$a = array('b' => '', 37 => false);
@@ -31,7 +31,7 @@ bool(false)
bool(false)
bool(true)
bool(true)
-bool(false)
+bool(true)
NULL
bool(true)
bool(true)
diff --git a/ext/standard/array.c b/ext/standard/array.c
index 8ebf4e1789..4d94c54ff1 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -6247,34 +6247,38 @@ PHP_FUNCTION(array_map)
Checks if the given key or index exists in the array */
PHP_FUNCTION(array_key_exists)
{
- zval *key; /* key to check for */
- HashTable *array; /* array to check in */
+ zval *key;
+ zval *array;
+ HashTable *ht;
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_ZVAL(key)
- Z_PARAM_ARRAY_OR_OBJECT_HT(array)
+ Z_PARAM_ARRAY_OR_OBJECT(array)
ZEND_PARSE_PARAMETERS_END();
+ if (EXPECTED(Z_TYPE_P(array) == IS_ARRAY)) {
+ ht = Z_ARRVAL_P(array);
+ } else {
+ ht = zend_get_properties_for(array, ZEND_PROP_PURPOSE_ARRAY_CAST);
+ }
+
switch (Z_TYPE_P(key)) {
case IS_STRING:
- if (zend_symtable_exists_ind(array, Z_STR_P(key))) {
- RETURN_TRUE;
- }
- RETURN_FALSE;
+ RETVAL_BOOL(zend_symtable_exists_ind(ht, Z_STR_P(key)));
+ break;
case IS_LONG:
- if (zend_hash_index_exists(array, Z_LVAL_P(key))) {
- RETURN_TRUE;
- }
- RETURN_FALSE;
+ RETVAL_BOOL(zend_hash_index_exists(ht, Z_LVAL_P(key)));
+ break;
case IS_NULL:
- if (zend_hash_exists_ind(array, ZSTR_EMPTY_ALLOC())) {
- RETURN_TRUE;
- }
- RETURN_FALSE;
-
+ RETVAL_BOOL(zend_hash_exists_ind(ht, ZSTR_EMPTY_ALLOC()));
+ break;
default:
php_error_docref(NULL, E_WARNING, "The first argument should be either a string or an integer");
- RETURN_FALSE;
+ RETVAL_FALSE;
+ }
+
+ if (Z_TYPE_P(array) != IS_ARRAY) {
+ zend_release_properties(ht);
}
}
/* }}} */