Variable scope problem accessing outer variable?

Prior to PHP 5.3, PHP only has two scopes: global and local function scope. PHP 5.3 introduced closures, which complicated the scope situation a bit, but it doesn't look like you're using them here Unlike many other C style programming languages, brackets/blocks do not invoke another level of scopre. The $a you declare at the start of the function is the same $a that you're accessing later.

If the value you're getting in $a is unexpected, it's the missing code (...) that's changing its value, either through an assignment or because it's being passed by reference into some other function that's changing its value.

You probably are using $a in a previous scope or func3() has set "global $a;" or maybe the if statements are never reached.

No that is only for func() – Granit Sep 7 '09 at 17:56 @Tim, someone with low self esteem downvoted everyone – w35l3y Sep 7 '09 at 20:57.

Global it. Global $a; func() { $a = 0; while() { echo $a; for() { if() { if() { $a = func3(); } } } } }.

Not complaining, just trying to understand better. – Tim Sep 7 '09 at 18:35 1. Because using a global scope is almost never the right answer.

2. The problem isn't a scope problem, since PHP doesn't create a new scope when it encounters a {} block. – Alan Storm Sep 7 '09 at 21:30 Alright, thanks!

I learned something today :) – Tim Sep 8 '09 at 18:33.

Prior to PHP 5.3, PHP only has two scopes: global and local function scope. PHP 5.3 introduced closures, which complicated the scope situation a bit, but it doesn't look like you're using them here. Unlike many other C style programming languages, brackets/blocks do not invoke another level of scopre.

The $a you declare at the start of the function is the same $a that you're accessing later. If the value you're getting in $a is unexpected, it's the missing code (...) that's changing its value, either through an assignment or because it's being passed by reference into some other function that's changing its value.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions