# New uint native data type?

- Thread: https://externals.io/message/65194
- Original archive: https://news-web.php.net/php.internals/65194
- Started by Marco Schuster on 2013-01-25T21:39:26+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #65194 — Marco Schuster — 2013-01-25T21:39:26+00:00

URL: https://externals.io/message/65194#65194

Hi all,

I'm currently writing a php-program to process certain special binary
files, which include 32-bit offsets which I need to read and
manipulate. The problem is that PHPs int type is only 31-bit because
they have sign information. Sure, I could use the GMP/bcmath stuff,
but that isn't really an option because of performance and the fact
that I'd have to use bc* functions everywhere, and the code is already
complex enough. Because I need to do maths and, later on, file
accesses at positions > 2GB, with them and not just print,
sprintf("%u",$val) is not sufficient, too.

Switching to 64-bit doesn't help in my case, as the program interfaces
with external windows-only dependencies and the PHP x64 build doesn't
do 64-bit ints at the moment.

Would it be possible to extend the PHP engine and add a "uint" native
type which allows handling of full 32-bit values and if yes, is there
any documentation about the parts of the engine I need to modify? The
PHP internals manual doesn't have much content and the Zend / main
directories in the source code lack useful information, too.

Thanks,
Marco

---

## #65195 — Rasmus Lerdorf — 2013-01-25T22:08:50+00:00

URL: https://externals.io/message/65194#65195 · In reply to: #65194

> Hi all,
> 
> I'm currently writing a php-program to process certain special binary
> files, which include 32-bit offsets which I need to read and
> manipulate. The problem is that PHPs int type is only 31-bit because
> they have sign information. Sure, I could use the GMP/bcmath stuff,
> but that isn't really an option because of performance and the fact
> that I'd have to use bc* functions everywhere, and the code is already
> complex enough. Because I need to do maths and, later on, file
> accesses at positions > 2GB, with them and not just print,
> sprintf("%u",$val) is not sufficient, too.
> 
> Switching to 64-bit doesn't help in my case, as the program interfaces
> with external windows-only dependencies and the PHP x64 build doesn't
> do 64-bit ints at the moment.
> 
> Would it be possible to extend the PHP engine and add a "uint" native
> type which allows handling of full 32-bit values and if yes, is there
> any documentation about the parts of the engine I need to modify? The
> PHP internals manual doesn't have much content and the Zend / main
> directories in the source code lack useful information, too.

No, this isn't something a quick patch will solve for you. It would
require changes throughout all of PHP and all the extensions.

For display purposes you can easily print these unsigned using
s/printf('%u',$val) and manipulation is possible too depending on what
sort of things you are trying to do to them.

If that isn't enough, writing a little custom extension to handle your
special case for these offsets is way way easier than modifying PHP to
add a new type.

-Rasmus
