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

Regression. Nested arrays throws array to string conversion in array_unique() #1561

Closed
Maks3w opened this issue Jan 14, 2014 · 4 comments
Closed

Comments

@Maks3w
Copy link

Maks3w commented Jan 14, 2014

This is a recent regression. This works good in 2.3.2 but not in master

var_dump(array_unique([[]]));
HipHop Notice: Array to string conversion in .... line ..
array(1) {
  [0]=>
  array(0) {
  }
}
@simonwelsh
Copy link
Contributor

The functions like array_unique work by converting all the items in them to strings then comparing, so an array to string notice is thrown.

The notice isn't thrown in this exact case by Zend since it looks like it special cases a singleton array as an argument. array_unique([[]. 'a']) in Zend throws the notice.

@simonwelsh
Copy link
Contributor

Actually, they don't special case it. This comes down to implementation differences.

Zend does the conversion to string each time it does a compare. HHVM starts by converting everything to a string, then comparing. So if there's multiple arrays, Zend throws a lot more warnings than HHVM.

@Maks3w
Copy link
Author

Maks3w commented Jan 14, 2014

@simonwelsh I don't know what are you trying to explain but the expected behavior (no notices) is the current Zend behavior and 2.3.2 behavior.

@scannell
Copy link
Contributor

Thanks for reporting this.

@simonwelsh is correct. I don't think we would want take the performance hit of repeated conversions to prevent the warning; this is a case where a PHP spec would help disambiguate what is contractual behavior and what is an implementation detail.

The warning is being raised for a reason: you are passing an array element inside an argument to array_unique and it is being converted to a string as part of the documented semantics of array_unique so the notice is reasonably expected behavior. We'll most likely end up wontfixing this as an intentional difference.

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

No branches or pull requests

4 participants