Author: F. Sanches
-
Important changes in PHP 8
Topic index on this page
- The way that automatic numbering works ( PHP 8.0)
- Comparison between numbers and strings ( PHP 8.0)
- The words ´match´ and ´mixed´ are now reserved keywords (PHP 8.0)
The way that automatic numbering works
If you create an array with the first key as a negative number, subsequent keys will add 1 to the previous number. Prior to PHP 8, subsequent keys after a negative number always started from zero.
<?php //php >= 8.x $myArray[-3] = 'R'; array_push($myArray, 'T', 'Y'); print_r($myArray); /*OUTPUT Array ( [-3] => R [-2] => T [-1] => Y )*/ //php < 8.x $myArray[-3] = 'R'; array_push($myArray, 'T', 'Y'); print_r($myArray); /*OUTPUT Array ( [-3] => R [0] => T [1] => Y ) )*/Comparison between numbers and strings
PHP 8 changes the way the loose comparison operator
==compares numbers to strings. Now it converting the number to a string and testing whether they’re the same.Before, the comparison was performed converting the string to a number, and it may seem bizarre, but previously any string compared no started in a numeral was converted to zero, what using the
==operator would return true. Now all this sentenses (0 == “not-a-number”) are false:0 == "foo"is false0 == ""is false0 == "0"is true0 === "0"is falseThe words ´match´ and ´mixed´ are now reserved keywords
-
What’s new in php 7
Topic index on this page
- Underscores in Integer & Floating notation (PHP 7.4)
- Spaceship operator (PHP 7.0)
Spaceship operator
<=>The spaceship operator
<=>is used for comparing two expressions.It returns:
-1when the left side is smaller0when the left side is equal1when the left side is greaterUnderscores in Integer & Floating notation
Like always, whole number, such as 3, 14, 22, or 2025 should not contain commas. However, since PHP 7.4, you can use underscores between digits for better readability, for example, 2_025. The PHP engine will remove the underscores automatically.
Floating point numbers (also known as floats, doubles, or real numbers) can be specified using decimal point, such as Pi 3.14159265359 or 2500.75, likewise, since PHP 7.4, you can use underscores between digits for better readability, for example, 2_500.75.