Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alexandre-daubois
Copy link
Member

@alexandre-daubois alexandre-daubois commented Aug 18, 2025

@alexandre-daubois alexandre-daubois force-pushed the array-key-exists-null branch 3 times, most recently from 472c3c6 to baeda1f Compare August 20, 2025 08:30
@@ -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");
Copy link
Member

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))?

Copy link
Member Author

@alexandre-daubois alexandre-daubois Aug 20, 2025

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
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member Author

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.

@alexandre-daubois alexandre-daubois force-pushed the array-key-exists-null branch 2 times, most recently from d5fd9e5 to a602268 Compare August 20, 2025 15:02
@alexandre-daubois
Copy link
Member Author

Still a few tests to fix but we're getting closer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants