1 year ago

#272018

test-img

Stefano Radaelli

php: unexpected pack("N")/unpack("N") behaviour with negative number

I have such script to pack and unpack a negative number:

<?
$from = -123456;
$to  = unpack("N", pack("N", $from));
echo $to[1] . "\n";;
?>

On an Linux host (RHEL 2.6.32-220.el6.x86_64) with PHP 5.4.7 $to[1] has the same value as input (-123456)

On another Linux host (RHEL 3.10.0-1160.42.2.el7.x86_64) with PHP 7.3.6 the $to[1] has value 4294843840.

What's wrong? Why PHP 7 is acting so?

php

32-bit

pack

unpack

0 Answers

Your Answer

Accepted video resources