Duplicates returned by array_unique when using enums #9775
Closed
Description
Description
The following code:
<?php
enum Test: string
{
case AUTHENTICATED = 'authenticated';
case COURSES_ADMIN = 'courses.admin';
case BUNDLES_ADMIN = 'bundles.admin';
case COURSES_REPORTING_ACCESS = 'courses-reporting.access';
case B2B_DASHBOARD_ACCESS = 'b2b-dashboard.access';
case INSTRUCTORS_ADMIN = 'instructors.admin';
case USERS_ADMIN = 'users.admin';
case COUPONS_ADMIN = 'coupons.admin';
}
$data = [
Test::COURSES_ADMIN,
Test::COURSES_REPORTING_ACCESS,
Test::BUNDLES_ADMIN,
Test::USERS_ADMIN,
Test::B2B_DASHBOARD_ACCESS,
Test::B2B_DASHBOARD_ACCESS,
Test::INSTRUCTORS_ADMIN,
Test::INSTRUCTORS_ADMIN,
Test::COUPONS_ADMIN,
Test::AUTHENTICATED,
];
$data = array_unique($data, flags: SORT_REGULAR);
var_dump($data);
Resulted in this output:
array(10) {
[0]=>
enum(Test::COURSES_ADMIN)
[1]=>
enum(Test::COURSES_REPORTING_ACCESS)
[2]=>
enum(Test::BUNDLES_ADMIN)
[3]=>
enum(Test::USERS_ADMIN)
[4]=>
enum(Test::B2B_DASHBOARD_ACCESS)
[5]=>
enum(Test::B2B_DASHBOARD_ACCESS)
[6]=>
enum(Test::INSTRUCTORS_ADMIN)
[7]=>
enum(Test::INSTRUCTORS_ADMIN)
[8]=>
enum(Test::COUPONS_ADMIN)
[9]=>
enum(Test::AUTHENTICATED)
}
But I expected this output instead:
array(10) {
[0]=>
enum(Test::COURSES_ADMIN)
[1]=>
enum(Test::COURSES_REPORTING_ACCESS)
[2]=>
enum(Test::BUNDLES_ADMIN)
[3]=>
enum(Test::USERS_ADMIN)
[4]=>
enum(Test::B2B_DASHBOARD_ACCESS)
[5]=>
enum(Test::INSTRUCTORS_ADMIN)
[6]=>
enum(Test::COUPONS_ADMIN)
[7]=>
enum(Test::AUTHENTICATED)
}
Quick preview:
https://3v4l.org/f3XVY#v8.1.11
PHP Version
PHP 8.1.11, 8.2rc3
Operating System
No response