Variable scope difference between PHP and C: block scope is not exactly the same?
Posted
by powerboy
on Stack Overflow
See other posts from Stack Overflow
or by powerboy
Published on 2010-05-24T00:19:11Z
Indexed on
2010/05/24
0:20 UTC
Read the original article
Hit count: 212
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?
© Stack Overflow or respective owner