7 Replies - 1071 Views - Last Post: 03 May 2016 - 07:31 AM

#1 astonecipher  Icon User is offline

  • Too busy for this
  • member icon

Reputation: 2343
  • View blog
  • Posts: 9,400
  • Joined: 03-December 12

Interesting truncation

Posted 02 May 2016 - 03:07 PM

Working on an issue I ran across what I can only see as an anomaly.

Take the following:
$ssn = [

    010119704455,
];
echo "<pre>";
print_r( $ssn );
echo "</pre>";


I cannot explain where that number comes from. I was thinking the size was too large for an int and truncating it. But, that is not what is going on from the value given.
Is This A Good Question/Topic? 0
  • +

Replies To: Interesting truncation

#2 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 879
  • View blog
  • Posts: 1,893
  • Joined: 30-January 09

Re: Interesting truncation

Posted 02 May 2016 - 04:19 PM

It's an octal number. Octal numbers are represented in the format 0nnn..., where nnn... is the number. As per the manual:

Quote

Warning
Prior to PHP 7, if an invalid digit was given in an octal integer (i.e. 8 or 9), the rest of the number was ignored. Since PHP 7, a parse error is emitted.

So, your number is being ignored once it hits the 9. 1011 from octal to decimal is 521.

CASE DISMISSED!
Was This Post Helpful? 3
  • +
  • -

#3 astonecipher  Icon User is offline

  • Too busy for this
  • member icon

Reputation: 2343
  • View blog
  • Posts: 9,400
  • Joined: 03-December 12

Re: Interesting truncation

Posted 02 May 2016 - 04:24 PM

Which brings much irritation. I guess as with most numeric account type numbers, it will need to be treated as a string.
Was This Post Helpful? 0
  • +
  • -

#4 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 879
  • View blog
  • Posts: 1,893
  • Joined: 30-January 09

Re: Interesting truncation

Posted 02 May 2016 - 04:27 PM

You should be treating it as a string anyway... how is it getting into the system as an integer with a leading zero? Not from a database or a form field, it would come in as string from those. And surely you're not explicitly declaring it in your code if it's an account type number.
Was This Post Helpful? 0
  • +
  • -

#5 astonecipher  Icon User is offline

  • Too busy for this
  • member icon

Reputation: 2343
  • View blog
  • Posts: 9,400
  • Joined: 03-December 12

Re: Interesting truncation

Posted 02 May 2016 - 04:49 PM

Not my code. I was explaining how an update was needed based on their expected values, hence the leading 0. It breaks down to a DoB with random 4 digits trailing.

I added it as a array field to validated several inputs on the regular expression being used.
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • say what now
  • member icon

Reputation: 6410
  • View blog
  • Posts: 25,909
  • Joined: 12-December 12

Re: Interesting truncation

Posted 02 May 2016 - 11:05 PM

Is it a DOB? Seems a little coincidental that it is the Unix epoch date.
Was This Post Helpful? 0
  • +
  • -

#7 astonecipher  Icon User is offline

  • Too busy for this
  • member icon

Reputation: 2343
  • View blog
  • Posts: 9,400
  • Joined: 03-December 12

Re: Interesting truncation

Posted 03 May 2016 - 04:19 AM

He told me the format and I used 1 Jan 1970. The numbers used for that one were me typing random numbers. The array started with 10 test cases.
Was This Post Helpful? 0
  • +
  • -

#8 Atli  Icon User is offline

  • Enhance Your Calm
  • member icon

Reputation: 4238
  • View blog
  • Posts: 7,216
  • Joined: 08-June 10

Re: Interesting truncation

Posted 03 May 2016 - 07:31 AM

View Postastonecipher, on 02 May 2016 - 11:24 PM, said:

I guess as with most numeric account type numbers, it will need to be treated as a string.

The problem in that line of thinking is considering it a "numeric account number" in the first place. That's technically an incorrect description, as it is in fact a series of separate, individual numbers. A date, a month, a year, and a random 4 digit number.

The 12 char end result is really a string of numbers, not a single numeric value, formatted for display. It should always be handled as a string in that format, regardless.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1