New PHP Function Str_Ends_With
PHP supports a number of functions for manipulating strings. Examples of these include strlen() to determine a string’s length, strrev() to reverse a string, and strpos() to search for a specific text within a string. These are helpful for developers in their daily jobs.
A new function added in PHP 8 is str_ends_with. This function checks if a given string ends with a certain other string, and it does so in a native and efficient manner. It requires two strings as parameters, and it returns a boolean value if the first string ends with the second string.
In previous versions of PHP, a string to number comparison would be performed by first casting the string into an integer or float, and then comparing that with a string. This is not ideal in many scenarios and can lead to bugs and security issues. This RFC makes string to number comparisons behave more like a standard string to string comparison.
It also adds support for properties in string literals. This will enable developers to create more readable code, and it will provide more flexibility when using string literals. It will also allow developers to make their code more self-documenting by letting them easily show what data they are using and how it is being used. It also makes it easier to use arrow functions, the null coalesce operator, and ternary and Elvis operators in string literals. Finally, it will also make inheritance errors due to mismatched method signatures throw a more meaningful error message.