Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

245
Views
Why does PHP not recognize the sequence of digits from PHP_INT_MIN as an integer

With

var_dump(PHP_INT_MIN);
//int(-9223372036854775808)

I get the number -9223372036854775808. If I assign this number to a variable, it is of the float type.

$n = -9223372036854775808;
var_dump($n);
//float(-9.2233720368548E+18)

This gives me integers:

$n = PHP_INT_MIN;
var_dump($n);
//int(-9223372036854775808)

and

$n = intval("-9223372036854775808");
var_dump($n);
//int(-9223372036854775808)

and

$n = sscanf("-9223372036854775808","%d")[0];
var_dump($n);
//int(-9223372036854775808)

Why does PHP give me a float type for -9223372036854775808 ?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Because the minus sign is not part of the syntax of a number in source code, it's the unary negation operator. So

$n = -9223372036854775808;

is treated like

$n = -(9223372036854775808);

But 9223372036854775808 is larger than PHP_INT_MAX, so it's parsed as a float, and then negated.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!