Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

246
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda