> Le 12 août 2020 à 20:19, Luis - SoftSAT Sistemas 
> <l...@softsatsistemas.com.br> a écrit :
> 
> In the effort to make PHP a better language i want to ask why not "fix" 
> nested functions as suggested in 
> (https://wiki.php.net/rfc/true-nested-function-support) or block their usage?
> The current behavior is a lot unexpected. 
> 
> I am new here, sorry if it was already discussed, i can't find a good way to 
> search the mailing history.
> 

Hi,

Defining a global function inside another function is not useless. Here is a 
dummy example:

```php
// a.php
spl_autoload_register(function ($classname) {
    if ($classname === 'Foo\\B')
        require 'foo/b.php';
})


// foo/b.php
namespace Foo;

class B {
    // ...
}

function some_helper(....$args) {
    // ...
}
```

The global function `Foo\some_helper` is defined inside the function used as 
autoloader.


Also, from the RFC:

> They exist in the global namespace.

I think you meant “They exist in the global scope”? because they are defined in 
the namespace corresponding to the eventual `namespace` declaration of the file.


—Claude
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to