tasoft/php-secure-int64-extension

v0.8.0 2022-03-31 15:13 UTC

This package is auto-updated.

Last update: 2022-07-01 00:07:21 UTC


README

I've created this package to handle UUIDs from MFRC511 module. It uses five byte ids which can not be represented by a 32bit system. (as Raspberry Pi is 32bit.)

Installation

$ cd ~
$ git clone https://github.com/tasoftch/php-secure-int64-extension.git
$ cd php-secure-int64-extension
$ phpize
$ ./configure --enable-secure-int64
$ make
$ sudo make install

This compiles the source on your machine.
Next find the php.ini file

$ php --ini

Will list scanned ini files.
Add the following line to that php.ini file: extension=secure_int64

<?php
var_dump( extension_loaded('secure_int64') ); // Should be true

Usage

The extension adds the following functions to the global scope:

  1. sint64_array_to_string
    Converts an array of maximal 8 bytes into a 64bit signed integer representation as string.
  2. uint64_array_to_string
    Converts an array of maximal 8 bytes into a 64bit unsigned integer representation as string.
  3. sint64_string_to_array
    Interprets a string as signed 64bit integer value and returns it as array, MSB first.
  4. uint64_string_to_array
    Interprets a string as unsigned 64bit integer value and returns it as array, MSB first.

Example

<?php
echo sint64_array_to_string([1]); // 1
echo sint64_array_to_string([1, 4]); // 260
echo sint64_array_to_string([0xFF, 0xFF]); // 65535

echo sint64_array_to_string([0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]); // 9223372036854775807
echo sint64_array_to_string([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]); // -1

echo uint64_array_to_string([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]); // 18446744073709551615

?>