Re: Endianness in PHP

From: Date: Thu, 12 Aug 2010 05:43:32 +0000
Subject: Re: Endianness in PHP
References: 1 2  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-7469@lists.php.net to get a copy of this message
Thanks for your response Alexey. I am aware of those functions but am really wondering if they are the way this is usually handled in PHP. The function htonl appears in the PHP Trunk in only about 10 places: http://lxr.php.net/search?q=htonl&project=PHP_TRUNK&defs=&refs=&path=&hist= My concerns are mostly about portability (see below).
Two questions: 1) Is there a standardized way or recommended best practice for conversions of ints, longs, and doubles to network byte order?
    
Usually, operating system provides functions for this. Look for the following functions: htonl, htons, ntohl, ntohs It's my understanding that these functions aren't always available. This link:
http://www.codeguru.com/forum/showthread.php?t=298741 says "'ntohs()', 'ntohl()', 'htons()', and 'htonl()' are not part of the C standard, and thus do not guarentee [sic] portability. " Also, my linux man pages say "These routines convert 16 and 32 bit quantities between network byte order and host byte order." Correct me if I'm wrong, but, PHP appears to use long rather than more specific data types like uint32_t. What happens when a long is 64 bits? Are these conversions valid for signed quantities? The docs all suggest they are for unsigned 16- or 32-bit ints. What about longs? What about doubles? I'm also wondering about the includes required for these functions. On *nix machines, it would appear to be: #include <arpa/inet.h> On windows, it would seem to be: #include <winsock2.h> Would that cover every platform where PHP is supposed to run? Seems to me PHP needs some standard way of handling this issue. If you insist these functions are the way to go, I will believe you, but that solution seems incomplete to me.
2) Can anyone recommend a cheap way to gain access to a Big-Endian machine for development and testing?
    
get old PowerPC mac ("mac mini G4" or something like that) Ugh. I was rather hoping I could get access to a VPS somewhere, perhaps through EC2 or Rackspace.com.


« previous php.pecl.dev (#7469) next »