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
DE478702 revert #3
Conversation
src/Mongator/Extension/Core.php
Outdated
@@ -1148,7 +1148,7 @@ private function parseAndCheckAssociationClass(&$association, $name) | |||
|
|||
private function mapArrayKeyWithDefault($array, $key, array $mapCallback, $default) | |||
{ | |||
if (property_exists($array, $key)) { | |||
if (array_key_exists($key, $array)) { |
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.
What was deprecated was usage on objects, not arrays, thus this may help:
if ((is_array($array) && array_key_exists($key, $array)) || (is_object($array) && property_exists($array::class, $key))) {
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.
@dberstein what about simply isSet($array[$key])
- didn't you say that fixes it? and it is a bit cleaner
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.
@ymalen isset
is not clear enough, if mixes key exists and non-nullness of value. On the other hand array_key_exists does exactly that: it tells if a key exists, regardless of its value.
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.
Simplified example where key exists (key "null") and isset
!= array_key_exists
:
$ php --version; php -r '$a=["null"=>null]; var_dump(isset($a["null"]), array_key_exists("null", $a));'
PHP 7.4.10 (cli) (built: Sep 3 2020 18:19:30) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Xdebug v2.9.7, Copyright (c) 2002-2020, by Derick Rethans
with Zend OPcache v7.4.10, Copyright (c), by Zend Technologies
Command line code:1:
bool(false)
Command line code:1:
bool(true)
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.
.
No description provided.