about int64 bug,when int variable set millisecond value then var_dump variable will see the type change to float type
busyfree opened this issue · 4 comments
busyfree commented
proto file define
message PayloadHead {
optional sint64 timestamp = 10;
optional sint32 nonce = 11;
optional string signature = 12;
}
protobuf-php generate file
<?php
/**
* Protobuf message : pb_global.PayloadHead
*/
class PayloadHead extends \Protobuf\AbstractMessage
{
/**
* @var \Protobuf\UnknownFieldSet
*/
protected $unknownFieldSet = null;
/**
* timestamp optional sint64 = 10
*
* @var int
*/
protected $timestamp = null;
/**
* nonce optional sint32 = 11
*
* @var int
*/
protected $nonce = null;
/**
* signature optional string = 12
*
* @var string
*/
protected $signature = null;
}
define the variable
<?php
public function payload()
{
$reqPayload = new Payload();
$head = new PayloadHead();
$timestamp = 1466165225000; //here int value
$head->setTimestamp($timestamp);
var_dump($head);
}
var_dump output
object(LivingPB\Payload\PayloadHead)#231 (17) {
["unknownFieldSet":protected]=>
NULL
["timestamp":protected]=>
**float**(1466165225000) //type changed
["nonce":protected]=>
int(312606)
["signature":protected]=>
string(40) "667fdc90ac64aa24a72ea444bffa532e96b3b5e6"
}
please check this issue.
thanks
FabioBatSilva commented
busyfree commented
Hi FabioBatSilva,
in protobuf-php/protobuf tests folder missing some requrie file ,so test case i can't run.now i create a test.proto file to test pb message object.
test.proto.txt
TestInt.php.txt
Test.php.txt
attach file extension need remove the .txt char.
please run this code and check the output.
my php version is PHP 5.5.10 and with gmp on centos i686.
thanks
FabioBatSilva commented
@geekcode If PHP encounters a number beyond the bounds of the integer type, it will be interpreted as a float instead. if you are running it in a 32 bit kernel the max int will be 2147483647
busyfree commented
thanks