Endianness in PHP
| From: | J. Adams | Date: | Thu, 12 Aug 2010 00:28:13 +0000 |
| Subject: | Endianness in PHP | ||
| Groups: | php.pecl.dev | ||
| Request: | Send a blank email to pecl-dev+get-7467@lists.php.net to get a copy of this message | ||
Two questions:
1) Is there a standardized way or recommended best practice for conversions of ints, longs, and doubles to network byte order?
2) Can anyone recommend a cheap way to gain access to a Big-Endian machine for development and testing?
The reason I ask is that I see that AMFEXT makes no effort to convert byte order when serializing an integer:
http://lxr.php.net/xref/PECL/amfext/amf.c#amf3_write_int
The AMF3 spec indicates that numbers are to be serialized in network byte order (i.e., "big-endian"). I see that Z_LVAL macros are used to extract the actual number data from a zval object or pointer to zval object by grabbing the contents of the zval's "lval" field which is declared as long. That function I linked, amf3_write_int, appears to work fine on a linux box with intel chip. I'm thinking it would break on a big-endian chip.
Any advice would be greatly appreciated!