What is strict type php?
From the Treehouse blog: Show
By default, PHP will cast values of the wrong type into the expected scalar type if possible. For example, a function that is given an integer for a parameter that expects a string will get a variable of type string. Strict types disabled (eval):
It is possible to enable strict mode on a per-file basis. In strict mode, only a variable of exact type of the type declaration will be accepted, or a TypeError will be thrown. The only exception to this rule is that an integer may be given to a function expecting a float. Function calls from within internal functions will not be affected by the strict_types declaration. To enable strict mode, the declare statement is used with the strict_types declaration: Strict types enabled (eval):
Working example: The default behavior in PHP is to attempt to convert scalar values of incorrect type into the expected type. For example, a function expecting a string can still be called with an integer argument, because an integer can be converted into a string as shown in the following example:
|