-
-
Notifications
You must be signed in to change notification settings - Fork 68
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
ArrayComparator ignores order - Part 2 #57
Comments
Woops, missed to bump it. |
This issue has been automatically marked as stale because it has not had activity within the last 60 days. It will be closed after 7 days if no further activity occurs. Thank you for your contributions. |
I bump it. |
There is a test for your use case so I think it is intended. See: comparator/tests/ArrayComparatorTest.php Line 47 in 5de4fc1
|
Fixed now? |
@sebastianbergmann Is fixed? |
There is nothing to fix here as @1blankz7 explained in #57 (comment). If you consider two associative arrays that have the same keys and the same values associated with these keys but a different order of elements to be different (I do not, the code does not) then you need to implement a custom comparator and use that. |
But isn't the definiton of Take for example this completely constructed code: $html = [
"h1" => "Greetings",
"p" => "How are you today?"
]
for ($html as $tag => $content) {
echo "<$tag>$content</$tag>";
} One would output: <h1>Greetings</h1>
<p>How are you today</p>
But if the equal test ignores order, we might end up with: <p>How are you today</p>
<h1>Greetings</h1>
What is the intended way to check that |
And how should the |
The description says: /**
* @param $canonicalize bool Arrays are sorted before comparison when set to true
*/ This indicates it would check the order. But it doesn't. Which is the problem noted here. I believe both code and test case are wrong here. When having However, if |
"Arrays are sorted before comparison when set to true" is meant to (only) apply to non-associative arrays. |
As in #44 mentioned the ArrayComparator ignore the order of two arrays, also if the attribute
$canonicalize = false
is set.The text was updated successfully, but these errors were encountered: