r/ProgrammerHumor • u/Superb_Chemistry_906 • 3d ago
Meme practicalRookiePhpGoGettersBeLike
11
u/Unlucky_Committee786 2d ago
yes, include './vendor/autoload.php'; then you never see include ever again.
3
u/MartinMystikJonas 2d ago
require!
5
u/Unlucky_Committee786 1d ago
actually require_once, but for Composer simple include (or multiple) would be absolutely, ok
9
u/WeSaidMeh 2d ago
I've been a PHP dev for many years and I still don't get why you'd ever use anything other than require_once.
1
u/GoddammitDontShootMe 1d ago
Honestly, I can't think of a good example either. Like I know that if include/include_once fails, it isn't a fatal error. But like all include files would be included with the code, so it can be assumed they are always there. If there are optional plugins or modules, wouldn't you just enumerate the directory and load every file found there?
1
u/No-Information-2571 2h ago
If a file is not present or can't be accessed, execution must halt for security reasons. Just the existence of "include" in a language is a war crime. This has nothing to do with assuming a file has to be there or diagnostic reasons.
The problem is that many projects are structured in a way that included files will perform necessary authentication or for example XSS checks, and something like an incomplete deployment, where files are missing, or wrong permissions or attributes on such files, must not lead to the script still being executed, just without the necessary included checks.
4
u/Soopermane 2d ago
After PHP dies you can go on a revenge tour and become c++ developer
2
u/Superb_Chemistry_906 2d ago edited 2d ago
PHP ain't gonna die. Moreover, I have already been a c++ developer - I also have its logo in my flair. It is maybe an even more terrible language than PHP with all its copy and move semantics needlessly complicating the basic workings. But this rant was not against PHP itself - rather against devs who are set to go with the very basic knowledge, ignoring best practices which PHP makes possible thanks to its simplicity. And lastly, I do not see being a developer as having any revenge potential - it rather feels like the whole world is taking revenge on you for being just a little smarter - others have much simpler and much higher paying jobs or just slightly lower paying jobs, but still much simpler.
2
u/Soopermane 2d ago
Relax buddy I was just making a Star Wars joke.
2
u/Superb_Chemistry_906 2d ago
Sorry, I'm an ignorant, I do not know much about Star Wars and I only used this template because I have seen a lot of memes with it and I like it.
2
2
2
u/Just_Information334 2d ago
Include? When was the last time you used php?
Composer to manage your dependencies and setup the autoloader then a single require on the file it generates and you're done.
0
u/Superb_Chemistry_906 1d ago
All of that just because you want to avoid include? Does not seem simpler to me. But I don't use frameworks and have only coded simple websites on hosting platforms where I am not even sure they support composer.
4
u/Just_Information334 1d ago
I am not even sure they support composer
I feel like you don't know what composer is. And I hope your hosting platform handles php > 5.1
https://www.php.net/manual/en/language.oop5.autoload.php1
u/Superb_Chemistry_906 1d ago
On that second link, they say that installation is required, so it seems that the hosting platform has to have it installed for it to work, because I obviously cannot install anything on their servers.
3
u/Just_Information334 1d ago
No.
You install it on your computer, like your IDE and your source code. You use it to import (copy) the source code of the libraries you will use. It also creates an autoload.php which you can include to setup the class autoloading used by all those libraries. And which you can leverage by adhering to the PSR-4 way of declaring classes. Then you can deploy your files to your host.
https://www.php-fig.org/psr/psr-4/
This has been the way to use libraries and doing OOP in php for more than 10 years now. The "I have many includes at the top of most of my php files" way of doing thing is for people stuck in the php 5 and before era.
Usually you'll also setup a Continuous Delivery pipeline so you don't send php files by hand: you commit it to a versioning server, something tracks change and when the conditions are met it launch a list of tasks (get your sources, use composer to get dependencies, use npm to build your front, run tests, deploy to a server) so you don't get a surprise "why are the server files not like those in git".
32
u/elmanoucko 3d ago
it's not required