static vars question
| From: | Martin Helie | Date: | Fri, 30 May 2003 20:49:00 +0000 |
| Subject: | static vars question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-149598@lists.php.net to get a copy of this message | ||
Sorry if this is completely stupid, but can anyone explain this, assuming
the following code:
function test() {
static $i = 0;
if( $i < 10 ) {
$i++;
test();
}
echo "I'm here";
}
test();
I am a little surprised to find that even when $i < 10 and test() is invoked
again, the current function call executes all the way through to echoing
"I'm here".
I would've thought current execution would be terminated as soon as the
function is called again, and that I'd get "I'm here" only once we're out
of
the loop (ie, $i == 10).
Thanks for any pointers.
Martin Helie