0

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'
3
  • 5
    you reached the maximum range of integer in 32-bit system it is 1 to 2147483647 and you have 6467838439. So when you try to convert it in integer type it is converted to the maximum range of int which is 2147483647. You can only store it as string Commented Jan 2, 2012 at 5:09
  • 1
    @Shakti Singh: how about float? Commented Jan 2, 2012 at 5:13
  • @zerkms: Yes, you can convert to float either. Commented Jan 2, 2012 at 5:15

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.