PHP: change order of object properties
问题 Regarding PHP, is there a way to change the order of object properties? class o {public $a = 1, $b = 2;} $o = new o; foreach (get_object_vars($o) as $k => $v) { print $k . '->' . $v . PHP_EOL; } Output: a->1 b->2 Existing public variables can be unset() , and added e.g. with $o->c = 3; . But array functions do not work with objects, and I do not want to convert the object to some stdClass. The only practical workaround I can think of is to decorate an array object and overload the magic __get