Skip to content
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

Merged
merged 2 commits into from Sep 22, 2020
Merged

DE478702 revert #3

merged 2 commits into from Sep 22, 2020

Conversation

avim9
Copy link

@avim9 avim9 commented Sep 22, 2020

No description provided.

@avim9 avim9 self-assigned this Sep 22, 2020
@@ -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)) {

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

Copy link

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

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.

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)

Copy link

@dberstein dberstein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@avim9 avim9 merged commit 25214ea into master Sep 22, 2020
@avim9 avim9 deleted the revert-array-key-exists-deprication branch September 22, 2020 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants