Bug #75259 [Com]: getTimestamp and ->format('U') both return 32-bit int

From: Date: Tue, 26 Sep 2017 13:45:36 +0000
Subject: Bug #75259 [Com]: getTimestamp and ->format('U') both return 32-bit int
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211359@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75259&edit=1 ID: 75259 Comment by: danack@php.net Reported by: lewiscowles at me dot com Summary: getTimestamp and ->format('U') both return 32-bit int Status: Not a bug Type: Bug Package: Date/time related Operating System: Ubuntu Xenial (64-bit) PHP Version: 7.0.23 Block user comment: N Private report: N New Comment: What date or time, do you think: new DateTime(PHP_INT_MAX << 1); is meant to result in? Previous Comments: ------------------------------------------------------------------------ [2017-09-26 13:44:22] requinix@php.net It works fine. https://3v4l.org/DigKO Do not use the regular date string parsing functions (eg, new DateTime and strtotime) with a Unix timestamp because they treat the input as a formatted time string. https://3v4l.org/K5cNb ------------------------------------------------------------------------ [2017-09-26 13:34:33] lewiscowles at me dot com Description: ------------ I expected to see > 32-bits (I'd really love to know how to get > 32bits of time-data if this is the expected behaviour) Test script: --------------- --- From manual page: http://www.php.net/datetime.gettimestamp --- <?php // PHP Get Integer Size (wouldn't expect 32-bit OS to deal with 64-bit Int's) var_dump(PHP_INT_SIZE); // setup $dt = new DateTime(PHP_INT_MAX << 1); // should return 64-bit max shifted left once var_dump(sprintf("%064b", $dt->format('U'))); // should return 64-bit max shifted left once var_dump(sprintf("%064b", $dt->getTimestamp())); Expected result: ---------------- // int(8) // string(64) "0111111111111111111111111111111111111111111111111111111111111111" // string(64) "0111111111111111111111111111111111111111111111111111111111111111" // Note I may have the zero in the wrong place, can't remember if the most or least significant bit is supposed to be shifted, but you get the picture). Actual result: -------------- // int(8) // string(64) "0000000000000000000000000000000001011001110010100111110111011010" // string(64) "0000000000000000000000000000000001011001110010100111110111011010" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75259&edit=1

« previous php.bugs (#211359) next »