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 false
0 == "" is false
0 == "0" is true
0 === "0" is false
Leave a Reply