3 ms·
To begin with, the fact the "module" system is tied to classes is a horrible design flaw. (Also in Java, but Java leans into it - PHP still has functions and lo
by morelisp 4y ago
To begin with, the fact the "module" system is tied to classes is a horrible design flaw. (Also in Java, but Java leans into it - PHP still has functions and lots of stuff is clearer as functions.)
- 9dev 4y ago…and you can have namespaces for functions and import namespaced functions just fine.
- morelisp 4y agoYou can namespace them, but you can't `use` them or otherwise autoload them.
- yurishimo 4y agoAre you sure? I've definitely written a `use` statement to import a function. https://www.php.net/manual/en/language.namespaces.importing.php https://www.php.net/manual/en/language.namespaces.importing....
- morelisp 4y agoAFAIK this only works if the function has already been loaded for some other reason (i.e. in the same file as a class or an explicit require). I do cop to not having used PHP recently, so maybe 8 fixed it? At least in the PHP I'm familiar with, nothing "happens" at `use` time; the first time you call a method on a class it autoloads. The autoloader is then what does the work of finding and requiring the file. No class, no autoloader.
- porker 4y agoPHP 8 hasn't fixed function autoloading, and Composer still has hacks like you can specify function containing files it will always load.