Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68730 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48311 invoked from network); 30 Aug 2013 16:27:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Aug 2013 16:27:56 -0000 Authentication-Results: pb1.pair.com header.from=leverton@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=leverton@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.176 as permitted sender) X-PHP-List-Original-Sender: leverton@gmail.com X-Host-Fingerprint: 209.85.192.176 mail-pd0-f176.google.com Received: from [209.85.192.176] ([209.85.192.176:40279] helo=mail-pd0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1E/03-32511-B08C0225 for ; Fri, 30 Aug 2013 12:27:55 -0400 Received: by mail-pd0-f176.google.com with SMTP id q10so2064995pdj.21 for ; Fri, 30 Aug 2013 09:27:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=cdzm3VFIx2+9l4W+pYF+UlFqZqzZf6HAZLBaepU7NxM=; b=m3nweWZ2EKnzZEMoq4yKJqhTb+kOz4VNX2nDDpMoHNKttUfjuBrPVLWps6xSJG2N+P M8aBzg8616PCiQYcx+nRWDC6EHpEiUdHRyALubIur0RiQBy4i6RmcCtJ8dUIBOuugA5T 4h+8W9MSCuaEIT1fcboJfpIHO6C+nAUGcH0L8Urft8S9+WcqRkDyitTvR/jToMrsYNto 4oPT0BA5z7+nXN6eFDzMdBHbXaudijtYVm94TjTnadPMcbpMK1xfi+V0aLFwk15K1z20 1G0JKL5u8Mt2iFUMZfEklJLBrDTNGaoF4n8UkrHqHsAjFvrS537QFBn1lpbm+UdYC1Tz +ivQ== MIME-Version: 1.0 X-Received: by 10.66.26.132 with SMTP id l4mr11706217pag.138.1377880072800; Fri, 30 Aug 2013 09:27:52 -0700 (PDT) Received: by 10.70.131.201 with HTTP; Fri, 30 Aug 2013 09:27:52 -0700 (PDT) In-Reply-To: References: Date: Fri, 30 Aug 2013 11:27:52 -0500 Message-ID: To: Rasmus Schultz Cc: PHP internals Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] Re: crc32() and ip2long() return values From: leverton@gmail.com (Matthew Leverton) On Fri, Aug 30, 2013 at 10:29 AM, Rasmus Schultz wrote: > No replies probably means no one cares. oh well. > > For the record, the examples I posted are wrong - the correct way to > convert the long values consistently appears to be: > > list($v) = array_values(unpack('l', pack('l', ip2long('255.255.255.0')))); > I had spotted the error, but didn't want to reply because I don't really understand what you are getting at. The core issue is that PHP doesn't provide a 32-bit unsigned integer on a 32-bit platform ... and/or that the size of integer changes depending on the platform. But I doubt that is going to change any time soon. Crippling 64-bit systems due to old, legacy 32-bit platforms is shortsighted. What's wrong with the manual's approach? $checksum = sprintf("%u", crc32("The quick brown fox jumped over the lazy dog.")); Are you going to do further mathematical operations on it? You can take that string and stuff it into an uint32 field into a db without an issue. At the end of the day, there's no getting around that PHP programmers need to be aware of the difference between 32-bit and 64-bit systems ... it affects far more than these two particular functions. But if these two functions are particularly bothersome, a better "fix" IMO is just: $crc = crc32("12341234", CRC32_UINT32_STRING); Where the second parameter is CRC32_INT (default & current behavior), CRC32_INT32 (always negative if high bit is set), CRC32_UINT32_STRING, CRC32_HEX_STRING Forgive the poor names. -- Matthew Leverton