Skip to content

Commit 0ba7c3e

Browse files
committed
Deprecate array_key_exists() on objects
1 parent b2ea507 commit 0ba7c3e

File tree

6 files changed

+38
-3
lines changed

6 files changed

+38
-3
lines changed

Zend/zend_execute.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,6 +2586,10 @@ static zend_never_inline uint32_t ZEND_FASTCALL zend_array_key_exists_fast(HashT
25862586
static zend_never_inline uint32_t ZEND_FASTCALL zend_array_key_exists_slow(zval *subject, zval *key OPLINE_DC EXECUTE_DATA_DC)
25872587
{
25882588
if (EXPECTED(Z_TYPE_P(subject) == IS_OBJECT)) {
2589+
zend_error(E_DEPRECATED, "array_key_exists(): "
2590+
"Using array_key_exists() on objects is deprecated. "
2591+
"Use isset() or property_exists() instead");
2592+
25892593
HashTable *ht = zend_get_properties_for(subject, ZEND_PROP_PURPOSE_ARRAY_CAST);
25902594
uint32_t result = zend_array_key_exists_fast(ht, key OPLINE_CC EXECUTE_DATA_CC);
25912595
zend_release_properties(ht);

ext/spl/tests/bug61347.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ var_dump(isset($b[37])); //true
2222
var_dump(isset($b['no_exists'])); //false
2323
var_dump(empty($b['b'])); //true
2424
var_dump(empty($b[37])); //true
25-
--EXPECT--
25+
--EXPECTF--
2626
bool(false)
2727
bool(false)
2828
bool(false)
2929
bool(false)
3030
bool(true)
3131
bool(true)
32+
33+
Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in %s on line %d
3234
bool(true)
3335
NULL
3436
bool(true)

ext/standard/array.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6330,6 +6330,9 @@ PHP_FUNCTION(array_key_exists)
63306330
ht = Z_ARRVAL_P(array);
63316331
} else {
63326332
ht = zend_get_properties_for(array, ZEND_PROP_PURPOSE_ARRAY_CAST);
6333+
php_error_docref(NULL, E_DEPRECATED,
6334+
"Using array_key_exists() on objects is deprecated. "
6335+
"Use isset() or property_exists() instead");
63336336
}
63346337

63356338
switch (Z_TYPE_P(key)) {

ext/standard/tests/array/array_key_exists.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,25 @@ Warning: array_key_exists(): The first argument should be either a string or an
280280
bool(false)
281281

282282
*** Testing operation on objects ***
283+
284+
Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in %s on line %d
283285
bool(false)
286+
287+
Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in %s on line %d
284288
bool(false)
289+
290+
Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in %s on line %d
285291
bool(true)
292+
293+
Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in %s on line %d
286294
bool(false)
295+
296+
Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in %s on line %d
287297
bool(true)
288298
bool(true)
289299

300+
Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in %s on line %d
301+
290302
Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
291303
bool(false)
292304
Done

ext/standard/tests/array/array_key_exists_object1.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,17 @@ var_dump($class2);
4646

4747
echo "Done";
4848
?>
49-
--EXPECT--
49+
--EXPECTF--
5050
*** Testing array_key_exists() : object functionality ***
5151

5252
-- Do not assign a value to $class1->var3 --
5353
$key = var1:
54+
55+
Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in %s on line %d
5456
bool(true)
5557
$key = var3:
58+
59+
Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in %s on line %d
5660
bool(true)
5761
$class1:
5862
object(myClass)#1 (3) {
@@ -66,6 +70,8 @@ object(myClass)#1 (3) {
6670

6771
-- Assign a value to $class2->var3 --
6872
$key = var3:
73+
74+
Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in %s on line %d
6975
bool(true)
7076
$class2:
7177
object(myClass)#2 (3) {

ext/standard/tests/array/array_key_exists_object2.phpt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,21 @@ var_dump($class2);
4848

4949
echo "Done";
5050
?>
51-
--EXPECT--
51+
--EXPECTF--
5252
*** Testing array_key_exists() : object functionality ***
5353

5454
-- Do not assign a value to $class1->var3 --
5555
$key = var1:
56+
57+
Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in %s on line %d
5658
bool(true)
5759
$key = var2:
60+
61+
Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in %s on line %d
5862
bool(false)
5963
$key = var3:
64+
65+
Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in %s on line %d
6066
bool(false)
6167
$class1:
6268
object(myClass)#1 (3) {
@@ -70,6 +76,8 @@ object(myClass)#1 (3) {
7076

7177
-- Assign a value to $class2->var3 --
7278
$key = var3:
79+
80+
Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in %s on line %d
7381
bool(false)
7482
$class2:
7583
object(myClass)#2 (3) {

0 commit comments

Comments
 (0)