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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners