Re: Return type hinting patch

From: Date: Sun, 27 Apr 2008 19:48:55 +0000
Subject: Re: Return type hinting patch
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.internals 
Request: Send a blank email to internals+get-37261@lists.php.net to get a copy of this message
Alain Williams wrote:
On Sat, Apr 26, 2008 at 05:11:29PM -0700, Chris Stockton wrote:
*cough* lambda *cough*
That would be nice, but the scoping of variables in PHP doesn't seem to make that nice, the code below results in '' Undefined variable: aa '' if I take the 'global' statement out, if I leave it in the echo in b() shows it as the empty string.
Because aa is not global in your example. Variables are either global or function-scoped in PHP. There is no such thing as a context or parent scope which is what you are looking for here.
Getting this right would be nice as it would allow (what has been explained to me at any rate) functional programming if a() returns an anonymous b(). The stuff below works in perl and python. function a($aa) {
    echo "a called aa=$aa\n";
    function b() {
        global $aa;
        echo "in b aa=$aa\n";
    }
    b();
} a('this is aa');


« previous php.internals (#37261) next »