The following PHP code will output 3.

function main() {
    if (1) {
        $i = 3;
    }
    echo $i;
}

main();

But the following C code will raise a compile error.

void main() {
    if (1) {
        int i = 3;
    }

    printf("%d", i);
}

So variables in PHP are not strictly block-scoped? In PHP, variables defined in inner block can be used in outer block?

Edit
Report