I would like to request new types in PHP. I would like to use 32-bit float and int numbers on 64-bit PHP. While we can keep the float and int as default 64-bit variables, we could have float32 and int32 types for 32-bit variables.

These 32-bit variables could help to consume less memory and not implementing custom rounding logic since the financial industry mostly uses 32-bit numbers including banks, e-commerce, ERPs. There are many cases when we don’t need scientific 64-bit types. We also could have float64 and int64 type signs that would be only aliases to the default int and float types. And if it’s possible 16bit and 8bit types also could be useful. This idea comes from Go, but it could go to PHP.
These 32-bit variables could help to consume less memory
No they wouldn’t. PHP variables are stored in a union of all possible types, the size of which is the size of it largest type (double).
With this in mind, there is no benefit to your suggestion.
https://github.com/php/php-src/blob/master/Zend/zend_types.h#L285
I believe the whole OP’s idea was to implement it the way it would consume less memory -> change the current zend engine behaviour.
However, would definitely help with implementing various crypto-currency protocols in PHP, although would also require support for signed and unsigned data types.
Yeah, if you’re concerned with memory, is PHP really the language you want to use?

(not a rhetorical question. answer would be appreciated)
These 32-bit variables could help to consume less memory
As a dynamically typed language PHP wraps values within a variant data structure which is basically a C-union + some extra fields carrying various info such as the current type. So you are anyway already paying for the largest native type and even more.
EDIT: @Sentient_Blade was faster than me.
If you a need a low memory footprint then you need memory density then you then need to have a full control over the memory layout. You could play with pack/unpack to replace the memory overhead by CPU overhead. You may also consider implementing the critical parts (in terms of memory or CPU) in another language.
These 32-bit variables could help to consume less memory and not implementing custom rounding logic since the financial industry mostly uses 32-bit numbers including banks, e-commerce, ERPs.
You should not use floating point numbers for money amount and everywhere you need a full / fixed precision. https://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency
To expand on floats for money, either use ints, (the amount of cents rather than dollars) or strings, my choice, and use PHP’s handy bcmath library.
The VPOS terminal I’m using with my bank had specifically instructed me to send the total sum as an integer/long regardless of the language that I use. They won’t accept any float/double number at all. The SDK would forbid it. Instead they kindly asked me to multiple/divide by 1000 and send that instead. I figured I’d save it that way too. I don’t know which banking software the OP is talking about. My bank is perfectly fine with accepting 64-bit integers.
Good point. What library you could recommend? I am looking for something like BigDecimal in Java.


These 32-bit variables could help to consume less memory and not implementing custom rounding logic since the financial industry mostly uses 32-bit numbers including banks, e-commerce, ERPs.
What’s worse: an integer that is larger than 32-bit max int, or an integer being implicitly converted to a float once it passes 32-bit int max? Because the latter is what PHP does. If the value of an int goes past PHP_INT_MAX, it gets converted to a float. And floats are inappropriate for financial math due to the lack of precision.
I am wondering what kind of system you are assigned to that runs oom on computing something.
I am afraid Santa already left. Maybe next year.
Members
Online

source