Just ask the title asks, here's the code:
<?php
$foo = 0;
function letsLoop() {
while ($foo != -1) {
changeFoo();
echo "Hello, world!
";
}
}
function changeFoo() {
extract($GLOBALS);
$foo = -1;
}
letsLoop();
Just ask the title asks, here's the code:
<?php
$foo = 0;
function letsLoop() {
while ($foo != -1) {
changeFoo();
echo "Hello, world!
";
}
}
function changeFoo() {
extract($GLOBALS);
$foo = -1;
}
letsLoop();
收起
Just because you extract the global into the local scope doesn't mean that you will be modifying the global variable $foo
. To reference the global variable inside the function, you must use the global
keyword:
function changeFoo() {
global $foo;
$foo = -1;
}
报告相同问题?