-
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?
baeda1f
to
a6d44e0
Compare
d5fd9e5
to
a602268
Compare
Still a few tests to fix but we're getting closer |
6f50c89
to
e508fcc
Compare
fd39b6d
to
8f22921
Compare
8f22921
to
dc5049b
Compare
@@ -2629,6 +2629,7 @@ static zend_never_inline uint8_t slow_index_convert(HashTable *ht, const zval *d | |||
ZEND_FALLTHROUGH; | |||
} | |||
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.
You will need to addref/delref ht
around this, because ht
may be freed by an error handler:
set_error_handler(function($errno, $errstr) {
global $ary;
$ary = null;
echo $errstr;
});
$ary[null] = 1; // AddressSanitizer: heap-use-after-free
See case IS_DOUBLE
as an example
@@ -2699,6 +2700,7 @@ static zend_never_inline uint8_t slow_index_convert_w(HashTable *ht, const zval | |||
ZEND_FALLTHROUGH; | |||
} | |||
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.
Here as well
@@ -3324,6 +3326,9 @@ static zend_never_inline bool ZEND_FASTCALL zend_array_key_exists_fast(HashTable | |||
} else if (Z_TYPE_P(key) <= IS_NULL) { | |||
if (UNEXPECTED(Z_TYPE_P(key) == IS_UNDEF)) { | |||
ZVAL_UNDEFINED_OP1(); | |||
} else { | |||
ZEND_ASSERT(Z_TYPE_P(key) == IS_NULL); | |||
zend_error(E_DEPRECATED, "Using null as the key parameter for array_key_exists() 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.
Probably here as well (I'm not sure)
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