-1

I have seen someone recently write million in the following way:

$myNumber = 1_000_000;

When I tried to use this in my PHP code I got the error:

Parse error: syntax error, unexpected '_000_000' (T_STRING), expecting ')' in /in/2MYCH on line 3

What is this notation?

James Z
  • 12,209
  • 10
  • 24
  • 44
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 1
    Versioning issues are covered by the canonical question for syntax errors. If it were necessary to specifically call this out a new question should not have been made. Instead a new answer on that canonical question would have been more appropriate. – John Conde Nov 30 '19 at 17:59

1 Answers1

1

Since PHP 7.4 you can use an underscore to separate the digits in a number.
See this RFC: https://wiki.php.net/rfc/numeric_literal_separator

This change has been implemented to make it easier for human eyes to tell how many digits there are in a numeric literal.

For example:

usleep(3500000); // Difficult: How many microseconds is this?
usleep(3_500_000); // Easy: This is 3.5 million

This notation works with all numeric literal notations supported by PHP, e.g. integers, floats, hexadecimal.

James Z
  • 12,209
  • 10
  • 24
  • 44
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • Typically, on such question, I would have commented *First result in [search](https://duckduckgo.com/?q=numeric+literal+separator+in+php)*, but great you brought this into attention – Victor Nov 29 '19 at 22:08
  • 1
    Not to belittle your _thorough research_, but this new feature is just one of the many interesting new features you can easily find and track on [migration](https://www.php.net/manual/en/migration74.new-features.php) – jibsteroos Nov 29 '19 at 22:12