Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

…and you can have namespaces for functions and import namespaced functions just fine.


You can namespace them, but you can't `use` them or otherwise autoload them.


Are you sure? I've definitely written a `use` statement to import a function.

https://www.php.net/manual/en/language.namespaces.importing....


AFAIK 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.


PHP 8 hasn't fixed function autoloading, and Composer still has hacks like you can specify function containing files it will always load.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: