Part 1 · Fundamentals / Typed locals
Lesson 2 of 8

Typed locals

Every local declaration has an explicit type and an initializer. The declaration creates mutable storage; assignments are checked against the declared type:

counter.ppphp
int $count = 0;
$count = $count + 1;   // ok

Bare assignment never declares a variable, so a typo cannot silently create a new one. The last assignment in the editor gives the int a string. Press Check and read the diagnostic, then fix it by assigning an int instead:

counter.ppphp
$count = 10;

Check again and the file passes. Press Run to see the program print the count.