I dream of a day where #PHP has some kind of (OPTIONAL) function/variable import/export system, if only to control scope in functional programs.
I dream of a day where #PHP has some kind of (OPTIONAL) function/variable import/export system, if only to control scope in functional programs.
@dandb Can you elaborate? Do you mean like what Python or JavaScript has with modules?
@ramsey Something like ES modules.
I can simulate it with returning arrays, etc, but it makes intellisense difficult and it's just clunky.
@dandb You want to import instances of objects that are exported from namespaces?
@ramsey not primarily concerned with objects tbqh, more functions and variables, especially variables holding closures
@dandb The concept of modules has been discussed, but it’s a hard problem to solve in PHP, with little benefit. Namespaces “imported” with the `use` statement are just class name aliases. The way classes are included is through the autoloading functionality, and most projects have adopted the PSR-4 autoloading standard because that’s what Composer uses, but autoloading has nothing to do with namespaces or even a directory structure (though PSR-4 uses that as part of its mechanism).
@ramsey That's kind of what I figured. It's something I only want very rarely, like when I want function composition. I've seen some discussions around function autoloading a while back and it seemed like something difficult to do. But a boy can dream 😅
@dandb The concept of “function autoloading” needs to be solved first. That would have to be followed by some kind of method for declaring exports for a given namespace, which implies that namespaces would need to become a real type of thing that could be introspected with reflection.