Tutorial by Examples

PHP is a loosely typed language. This means that, by default, it doesn't require operands in an expression to be of the same (or compatible) types. For example, you can append a number to a string and expect it to work. var_dump ("This is example number " . 1); The output will be: ...
When reading from a file, we want to be able to know when we've reached the end of that file. Knowing that fgets() returns false at the end of the file, we might use this as the condition for a loop. However, if the data returned from the last read happens to be something that evaluates as boolean f...
Switch statements use non-strict comparison to determine matches. This can lead to some nasty surprises. For example, consider the following statement: switch ($name) { case 'input 1': $mode = 'output_1'; break; case 'input 2': $mode = 'output_2'; bre...
Since PHP 7.0, some of the harmful effects of type juggling can be mitigated with strict typing. By including this declare statement as the first line of the file, PHP will enforce parameter type declarations and return type declarations by throwing a TypeError exception. declare(strict_types=1); ...

Page 1 of 1