Aramael Pena-Alcantara
Aramael Pena-Alcantara

Reputation: 368

PHP Typecasting Error Changing Value

I am trying to store a phone number and I have reached some problems due to type casting? Anyone have any suggestions as to what is happening here?

var_dump((int)"6467838439"); // displays 'int 2147483647'

Upvotes: 0

Views: 109

Answers (2)

Shawn Janas
Shawn Janas

Reputation: 2743

An integer is 32 bits and has a finite size of approximatly 2 billion so your phone number is being truncated. You should store it as a string.

Upvotes: 1

Kenaniah
Kenaniah

Reputation: 5201

Phone numbers should be stored as text. They generally can't be stored as integers due to integer overflow.

Upvotes: 4

Related Questions