Part 1 · Fundamentals / Typed locals
Lesson 2 of 8

Typed locals

Give each local variable a type and a starting value. Here, int means $count holds an integer. You can change its value later, but each new value must still be an integer:

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.