-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Deprecate using null as an array offset and when calling array_key_exists()
#19511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Deprecate using null as an array offset and when calling array_key_exists()
#19511
Conversation
b1629ed
to
6b521a3
Compare
472c3c6
to
baeda1f
Compare
ext/standard/array.c
Outdated
@@ -6981,6 +6981,7 @@ PHP_FUNCTION(array_key_exists) | |||
RETVAL_BOOL(zend_hash_index_exists(ht, Z_LVAL_P(key))); | |||
break; | |||
case IS_NULL: | |||
zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we have different messages for using array offset ($foo[null]
) and array key exists (array_key_exists(null, $foo)
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed "Using null as the key parameter for array_key_exists() is deprecated, use an empty string instead". What do you think?
@@ -7,5 +7,6 @@ Bug #20865 (array_key_exists and NULL key) | |||
|
|||
var_dump(array_key_exists(NULL, $ta)); | |||
?> | |||
--EXPECT-- | |||
--EXPECTF-- | |||
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there should be 2 deprecation messages here, one from the $ta[NULL]
and one from the array_key_exists, which makes me suspect that the array offset usage isn't emitting a warning
can you also add dedicated tests for the array offset usage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started to add the warning for $ta[NULL]
as well, but actually, it seems the RFC doesn't mention this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah wait, actually it does, I missed the last bit of the sentence. My bad, let's add the message.
baeda1f
to
a6d44e0
Compare
d5fd9e5
to
a602268
Compare
Still a few tests to fix but we're getting closer |
a602268
to
6f50c89
Compare
Part of #19468
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_using_values_null_as_an_array_offset_and_when_calling_array_key_exists
cc @Girgias