====== PHP RFC: Add pack()/unpack() endianness modifiers for floating-point numbers ====== * Version: 1.0 * Date: 2026-01-16 * Author: Alexandre Daubois, * Status: Under discussion ===== Introduction ===== This RFC proposes extending the endianness modifier syntax (< and >) to floating-point format codes in PHP's pack() and unpack() functions. Currently, PHP's pack/unpack functions support floating-point numbers only with machine-dependent byte order: * f - single-precision float (4 bytes, machine byte order) * d - double-precision float (8 bytes, machine byte order) * g/G - single-precision float (little/big endian) * e/E - double-precision float (little/big endian) While PHP already has endian-specific letters for floats (g/G/e/E), the modifier syntax (f</f>/d</d>) provides consistency with [[pack-unpack-endianness-signed-integers-support|the endianness modifier syntax]] introduced in PHP 8.6. ===== Perl Specification Reference ===== According to the Perl documentation (https://perldoc.perl.org/functions/pack), Perl supports endianness modifiers on floating-point format codes: f< single-precision float, little-endian byte order f> single-precision float, big-endian byte order d< double-precision float, little-endian byte order d> double-precision float, big-endian byte order ===== Proposed Solution ===== This RFC proposes adding endianness modifiers to floating-point format codes: * f</f> for single-precision float (4-byte, little/big endian) * d</d> for double-precision float (8-byte, little/big endian) **Example usage:** d>', 3.14159, 2.71828); // Unpacking [$float, $double] = array_values(unpack('f **Equivalence with Existing Formats:** ', 3.14) === pack('G', 3.14); pack('d<', 3.14) === pack('e', 3.14); pack('d>', 3.14) === pack('E', 3.14); ?> ===== Error Handling ===== Modifiers on formats with inherent endianness (g/G and e/E) will emit a ValueError, for example: ===== Backward Incompatible Changes ===== None. The modifier syntax is opt-in and does not affect existing format strings. ===== Proposed PHP Version(s) ===== PHP 8.6 (next minor) ===== Voting Choices ===== Yes / No vote requiring 2/3 Yes votes to pass. * Yes * No ===== References ===== * Integer endianness modifiers RFC: https://wiki.php.net/rfc/pack-unpack-endianness-signed-integers-support * Perl pack documentation: https://perldoc.perl.org/functions/pack * PHP pack documentation: https://www.php.net/manual/en/function.pack.php