Re: Variable scope - function in function
- From: "Rik" <luiheidsgoeroe@xxxxxxxxxxx>
- Date: Sun, 21 May 2006 23:17:49 +0200
Chung Leong wrote:
Paul Lautman wrote:
Here's something that I can't manage to find explicitly documented.
In the following snippet:
function outer() {
global $a;
function inner() {
global $a;
echo $a.'1<br>';
}
$a = 's';
inner();
echo $a.'2<br>';
}
outer();
If either of the globals statements is removed, the variable is not
accessable within inner.
Which is abolutely logical.
What you're trying to do won't work if you call outer() more than
once.
PHP has no support for closure or inner functions.
You could circumvent this by:
if(!function_exists('inner'){
//define function
}
I'm very curious though why one would need such an imho messy function
declaration.
Grtz,
--
Rik Wasmus
.
- Follow-Ups:
- Re: Variable scope - function in function
- From: Paul Lautman
- Re: Variable scope - function in function
- References:
- Variable scope - function in function
- From: Paul Lautman
- Re: Variable scope - function in function
- From: Chung Leong
- Variable scope - function in function
- Prev by Date: Re: Check before insert in Database
- Next by Date: Re: Check before insert in Database
- Previous by thread: Re: Variable scope - function in function
- Next by thread: Re: Variable scope - function in function
- Index(es):
Relevant Pages
|