Discovering Other PHP 8 Usage Changes

Learn about typecasting and adding comments principles introduced in PHP 8.

There are a number of program code usage changes that we need to be aware of in PHP 8. We’ll start with a look at two typecasts that are no longer allowed.

Removed typecasts

Developers often use forced typecasts in order to ensure the data type of a variable is appropriate for a particular usage. As an example, when processing an HTML form submission, for the sake of argument, let’s say one of the form elements represents a monetary amount. A quick and easy way to sanitize this data element is to typecast it to a float data type, as follows:

Get hands-on with 1200+ tech skills courses.