3 ms·
> This also can change over time. For example, 15 years ago PHP shepherded you to include every file you were using explicitly, making it hard to reason about a
by pitterpatter 7y ago
> This also can change over time. For example, 15 years ago PHP shepherded you to include every file you were using explicitly, making it hard to reason about a given project if you weren’t the creator.
Huh, that seems backwards to me? Wouldn't the explicit approach make it more obvious what scripts were relevant?
- toast0 7y agoThat's been my experience; in the before times, I could step in and look at a server with issues and easily find the source (as long as nobody was too clever about paths), with autoloading I just have to grep the whole thing and hope. I don't like a lot of what 'Modern PHP' has become though, so clearly the community is going a different direction without me, and I guess it's working for them.
- earthboundkid 7y agoYes, modern PHP is different and better than the PHP everyone cranked out in the 00s, but auto-importing is orthogonal to the improvements. The big change is to use classes everywhere.
- muglug 7y agoUsing classes everywhere was made much easier with the auto-importing. In fact the auto-importing means that regular functions (which have no auto-importing mechanism) are now used less than they probably should be.
- muglug 7y agoOftentimes not, because you'd end up importing everything as a precautionary measure, and there was a big temptation to mix together many classes and functions in the same file.
- arthens 7y agoAs someone who has written a lot of PHP and is still maintaining a few PHP codebases... I don't miss the old ways at all. But I can see how the parent comment can be misleading for someone who's not too familiar with PHP (apologies if my assumption is wrong). TL;DR in many ways modern PHP is more explicit than old PHP The old way wasn't as explicit as the comment makes it. It was just painful. Imports in PHP are global, so every file can use any function/class already imported. You could explicitly define all dependencies at the top, but that's not what the language shepherds you to. In reality most imports were implicit (explicit in ANOTHER file), and you'd just import what you needed that hadn't been already imported (I don't think I've ever worked in a codebase where every file has all dependencies declared at the top). The old ways had so many downsides: - moving things around could produce fatal errors just because the implicit imports changed - any framework/cms using require instead of requice_once would limit your ability to import files (including the same class twice creates a fatal error) - very poor support for IDEs The modern way is quite pleasant to work with: - everything should be in a namespace - every used class should be declared at the top of the file (like Java) - great IDE support (auto imports, auto complete, click to go to definition) Yes there's some extra complexity in the autoloader, but in my experience it's negligible. If you use an IDE you might never even see it. So yeah I don't think PHP got any less explicit. The opposite actually, modern libraries/frameworks tend to be much easier to navigate.
- muglug 7y agoYeah, my explanation wasn't good. Yours is much better – thanks! If anyone's curious what the old way looks like, have a look at WordPress's codebase – lots of imports scattered around everywhere with no one single class-loading system.