Lesson content
Read, practise, then check your understanding
Variables begin with $ and are case-sensitive. Values include bool, int, float, string, array, object, resource, callable, iterable, and null. Runtime types can change unless declarations constrain them.
Practical example
<?php
$count = 7;
$ratio = 0.75;
$active = true;
$items = ['forms', 'PDO'];
if (!is_int($count)) { throw new TypeError('integer required'); }
Use get_debug_type for diagnostics and is_* predicates for contracts. Type juggling can surprise comparisons and arithmetic, so validate external data and prefer strict equality. Nullable, missing, empty, and invalid are different domain states.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.