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

No return from array_unique() with Nested arrays halts and throws array to string conversion #7239

Closed
photodude opened this issue Jul 20, 2016 · 10 comments

Comments

@photodude
Copy link
Contributor

photodude commented Jul 20, 2016

HHVM Version 3.12.5 / 3.14.3 / 3.18.1

Standalone code, or other way to reproduce the problem

No return from array_unique() with Nested arrays halts and throws array to string conversion

Happens with two nested arrays merged and made unique

array_unique(array_merge($this->_links, $data['links']))

<?php
error_reporting(E_ALL);
$b = array(
  'index.php' =>
  array(
    'relation' => "Start",
    'relType'  => "rel",
    'attribs'  => array(),
  )
);
$c = array(
  'index.php' => 
  array(
    'relation' => "Start",
    'relType'  => "rel",
    'attribs'  => array(),
  )
);
$u = array_unique(array_merge($b,$c));

Related issue #1561

Expected result

Should return a new array without duplicate values ignoring internal array to string conversion notices from the nested arrays

Actual result

no array is returned, just the array to string conversion notice is thrown

@simonwelsh
Copy link
Contributor

PHPUnit converts notices to exceptions, so this looks like it's working as expected. If you're not using an error handler that converts everything to exceptions, you get the array returned.

https://3v4l.org/Mcd7d

@photodude
Copy link
Contributor Author

photodude commented Jul 20, 2016

@simonwelsh I've looked into the information you noted on "PHPUnit converts notices to exceptions" I'm not sure I agree that is the whole issue. Based on your information I would have to assume that my other HHVM php7 compatibility issue is related to "PHPUnit converts notices to exceptions", yet when in testing with just PHP7 we get the notices but tests continue.

Seems to me that there is something more going on than just "PHPUnit converts notices to exceptions" which is causing HHVM to halt or not return values.

@aorenste
Copy link
Contributor

It seems like the underlying problem is that array_unique() is complaining about an array to string conversion when it shouldn't.
https://3v4l.org/16RgR

@nikic
Copy link
Contributor

nikic commented Sep 29, 2016

@aorenste PHP is simply special-casing the <= 1 elements case, in which case it directly returns the array. It does throw the notice for more elements: https://3v4l.org/kvaEq

@photodude
Copy link
Contributor Author

photodude commented Sep 29, 2016

this was my original test case https://3v4l.org/OfMqV

this is a modified version of that test case following @nikic 's changes https://3v4l.org/vHUAv

@photodude
Copy link
Contributor Author

Here is a test case that uses SORT_REGULAR as a workaround solution similar to what we implemented
https://3v4l.org/aqsrn

It seems to work for hhvm 3.15+ but causes Uncaught exception: std::bad_alloc on hhvm 3.14.4

@Orvid
Copy link
Contributor

Orvid commented Nov 14, 2016

@photodude The hhvm 3.14.4 error is an issue with 3v4l.org's config currently. :(

@photodude
Copy link
Contributor Author

@Orvid is the hhvm 3.14.4 config issues on 3v4l related to 3v4l enabling the hhvm php7 mode ? see this item https://3v4l.uservoice.com/forums/219058-general/suggestions/16257685-hhvm-in-php-5-mode

@photodude
Copy link
Contributor Author

Looks like this is still an issue with HHVM 3.18.1

@photodude
Copy link
Contributor Author

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

5 participants