I understand little & big endian, but What's "machine byte order" mean?
-
2is this a question or a statement? – Dave Lasley Sep 14 '12 at 19:22
-
1It means the byte order of the machine it's running on. – Travesty3 Sep 14 '12 at 19:23
-
possible duplicate of [When would you use unpack('h*' ...) or pack('h*' ...)?](http://stackoverflow.com/questions/3857499/when-would-you-use-unpackh-or-packh) – mario Sep 14 '12 at 19:26
-
1It means PHP will pack in whatever order the underlying machine it's running on uses, meaning pack will produce different results on different platforms, using the exact same code. – Marc B Sep 14 '12 at 19:26
-
@MarcB so, for unpack() this doesn't affect? – iamart Sep 15 '12 at 09:17
1 Answers
In pack the phrase "machine byte order" means that the endianess is determined by the current machine1
PHP itself makes no guarantees as to which endianness such characters (e.g. S, L) encode data, except as the ordering relates to the current machine.
Therefor, be cautious with using "machine byte order" pack characters and consider the guaranteed-order counter-parts (e.g. n, v) if there is every any doubt1. However, pay attention to the target data specification as some silly formats like [Microsoft] UUIDs are laid out in terms of "machine byte order" while others are always big-endian or always little-endian.
1 x86/x64 is always little-endian, but PHP could technically run on big-endian machines .. somewhere. It is best to get into the habit of being explicit and precise to avoid having code suddenly and mysteriously "stop working" later on.