Re: Nested functions

From: Date: Wed, 12 Aug 2020 19:00:58 +0000
Subject: Re: Nested functions
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-111496@lists.php.net to get a copy of this message
> Le 12 août 2020 à 20:19, Luis - SoftSAT Sistemas <luis@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

« previous php.internals (#111496) next »