<?php
class Point
{
public function __construct(
private int $y,
private int $x,
private string $debug,
) {}
}
// Order is intended to be like ORDER BY x, y
// Because the order properties are declared, it becomes ORDER BY y, x
$data = [
new Point(3,1,'should be third'),
new Point(1,1,'should be first'),
new Point(1,2,'should be fourth'),
new Point(2,1,'should be second'),
];
sort($data);
print_r($data);
Array
(
[0] => Point Object
(
[y:Point:private] => 1
[x:Point:private] => 1
[debug:Point:private] => should be first
)
[1] => Point Object
(
[y:Point:private] => 1
[x:Point:private] => 2
[debug:Point:private] => should be fourth
)
[2] => Point Object
(
[y:Point:private] => 2
[x:Point:private] => 1
[debug:Point:private] => should be second
)
[3] => Point Object
(
[y:Point:private] => 3
[x:Point:private] => 1
[debug:Point:private] => should be third
)
)