Scalar type hints

By classification, PHP is a dynamically typed and weakly typed language. These are two different concepts that often get mixed together. Dynamically typed languages do not require the explicit declaration of a variable before it is used. Weakly typed languages are those in which the variable is not of any specific data type, that is, its type can change through different value-type reassignments.

Let's take a look at the following example:

// dynamic typed (no specific type defined, directly assigning value)$name = "Branko"; // string$salary = 4200.00; // float$age = 33; // int// weak typed (variable value reassigned into different type)$salary = 4200.00; // float$salary = $salary + "USD"; // float$salary = $salary . "USD"; ...

Get Mastering PHP 7 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.