rfc:64bit-integer-type

Request for Comments: 64-bit Integer type

This RFC is about adding a 64bit integer type to PHP.

Introduction

Currently PHP's int type is 32bit on x86 systems, and 64bit on x64 systems. Sometimes you will need to handle numbers thats bigger than the 32bit integer limit and have to either use dirty hacks like converting to a float/string or use extensions like BCMath for such operations.

This RFC proposes a new type (“int64”), which always is 64bit long no matter the host arch.

User land

Declarings

To remain consistent and not changing the current integer type declarings, a new prefix will be available for declaring 64bit long integers:

<?php
$int64 = L199938937393792738748327842;
 
var_dump($int64, L209938836626262738748327842);
 
/*
int64(199938937393792738748327842)
int64(209938836626262738748327842)
*/
?>

Type casts

Like the integer type, you may also cast to a 64bit integer:

<?php
 
$int64str = '199938937393792738748327842';
 
var_dump((int64) $int64str);
 
/*
int64(199938937393792738748327842);
*/
?>

The type cast have a “long” name alias too: (integer64)

Functions

New function(s) should be inserted into the core

  • is_int64 (Or maybe the is_int function should me modified)

Internals

Data type

The 64bit integer will internally be stored as 'zend_long64', as currently defined in zend_types.h

API

The API will be identical to the current type handling functions/macros that already exists:

  • RETURN_LONG64
  • IS_LONG64
  • convert_to_long64()
  • etc.

Parameter parsing

To parse the 64bit integer via the parameter_parsing API, the 'i' modifier will be in place like the 'l' for 'long'. Aswell as the 'I' modifier for limiting out of range values to minimum/maxmimum values of a zend_long64

Patch

Currently no patch is available, but it is in the works.

rfc/64bit-integer-type.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1