Source: www.amitmerchant.com

Strict typing vs. Weak typing in PHP

Category: PHP, javascript

A blog on PHP, JavaScript and more Amit Merchant · June 1, 2020 · ⋆ PHP If the given value is of the incorrect type, then an error is generated: in PHP 5, this will be a recoverable fatal error, while PHP 7 will throw a TypeError exception.

So, now, whenever the method sum is called, PHP would expect to get the respective parameters of specified types.

In other words, PHP will try to “fallback” to the supplied type to the target type whenever it can.

PHP will try to coerce “3.5” to its integer value which is happen to be 3 in this case and process it further accordingly.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners