-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[PropertyAccess] array_keys does not work for ArrayAccess objects #10705
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
Conversation
please add a test covering this and please add the PR summary table in the description |
If |
@stof Will do when I get back to work tomorrow. |
@sandermarechal any news on this PR? |
Can you also take care of the case where the var is Traversable? |
Done. Note: I don't know why fabbot's Travis build fails. The error if gives doesn't match my source code. Perhaps this is caused by the same reason that I cannot rebase this on master without causing a conflict? |
if (is_array($objectOrArray)) { | ||
$keys = '"' . print_r(array_keys($objectOrArray), true) . '"'; | ||
} elseif ($objectOrArray instanceof \Traversable) { | ||
$list = []; |
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 be array()
to keep BC with PHP 5.3.
foreach ($objectOrArray as $key => &$value) { | ||
$list[] = $key; | ||
} | ||
$keys = '"'.print_r($list, 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.
I'd use implode() with ", "
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.
The original code also used print_r() so I left it that way.
Hi @sandermarechal, thank you for your work on this issue! I fixed this, together with a few other improvements, in #10946 and #10947. |
The array_keys() function does not work on objects implementing \ArrayAccess. Skip listing the known properties for such objects.