this post was submitted on 16 Jun 2023
72 points (100.0% liked)

Programming

13383 readers
1 users here now

All things programming and coding related. Subcommunity of Technology.


This community's icon was made by Aaron Schneider, under the CC-BY-NC-SA 4.0 license.

founded 2 years ago
MODERATORS
 

I don't know if it's due to over-exposure to programming memes but I certainly believed that no one was starting new PHP projects in 2023 (or 2020, or 2018, or 2012...). I was under the impression we only still discussed it at all because WordPress is still around.

Would a PHP evangelist like to disabuse me of my notions and make an argument for using PHP for projects such as Kbin in this day and age?

top 50 comments
sorted by: hot top controversial new old
[–] [email protected] 29 points 1 year ago (6 children)

I'm a web developer of 25+ years. These days python, php, react, vue stack. Formerly, C, C++, perl and assorted other oddities.

Forget what you once heard about PHP. Modern php is nothing like its early days. Modern php has some great constructs that give language expressiveness and fluidity, and that really lends itself to concise and beautiful code.
PHP also has some brilliant web frameworks (eg: Symfony) that make build web apps (be it REST APIs or frontend backends) just a pleasant experience all around. It's dead simple yet extremely powerful. This makes makes development and maintenance using PHP cheap. PHP's testing suite is also ridiculously powerful.

By comparison, I find python web frameworks (Django, flask etc), fiddly and finnicky to use. I also find Python a much less expressive language. By that I mean it will often take me several lines of code to do something that is otherwise a 1 liner in php. It just feels clunky and awkward.

Don't get me wrong. I once hated and laughed at PHP with the rest of them. But PHP has really evolved over the past 10 years, much more so than python has. I look forward to the day Python has a good hard look at itself.

In the meantime, if I need a backend for a website and I'm given the choice between PHP or Python, I'll choose PHP (symfony) every time.

Besides, PHP devs are cheaper.

[–] [email protected] 4 points 1 year ago

Thank you for the detailed response and don't worry: you don't have to pull punches on Python on my account πŸ˜‚ I'm a former Django dev and I have no intention of working with Python ever again. I see why it's so popular for data analysis etc.: it's a phenomenal language for non-programmers.

load more comments (5 replies)
[–] [email protected] 21 points 1 year ago (1 children)

I see a lot of people quick to hate on PHP while not really knowing anything about it's modern usage... but the thing I think of most is how people praise Lemmy for using Rust and diss Kbin for using PHP, but at the end of the day it's HOW those tools are used that determines the quality of something. Language changes, but fundamentals stay the same, and in the end all anyone should care about is whether or not something works.

Programming language wars have always seemed a tad shallow to me.

[–] [email protected] 9 points 1 year ago

This is absolutely the truth. Ruby (Mastodon) and PHP are far more than enough to get the job done, and being good at your job (building a product) is more important than using the latest or greatest tools.

That said, these examples often have great existing products and communities keeping them in the conversation. OCaml is good enough for Jane Street but that doesn't mean it's the best or go choice. Such wars or discussions are definitely shallow when focused exclusively on the syntax and semantics

[–] [email protected] 17 points 1 year ago

First off, any language/framework is just a tool.

Second, modern PHP is quite different than 2005 PHP which is about when people started moving to other languages for web development (Ruby, Python, etc.). What you can and should write in PHP today would be almost identical to what it would look like in those languages (i.e. MVC frameworks, ORM for DB access, dependency management with lock files). Many language features were added too such as namespacing which allow for better/modern code organization.

PHP has always had (and never lost) it's dead simple capability to just package up a tar ball, ftp, unzip and just... run.

Would I use PHP today, not unless forced to or for a lot of money. But if it's a language a team knows, there isn't a benefit to switching to something else.

[–] [email protected] 16 points 1 year ago (2 children)

I don't know too much about PHP (aside from it getting memed on constantly), but kbin is built using the Symfony framework, which is really performant and mature based on what I've heard from others. Also, apparently ~80% of all websites (that W3techs knows about) rely on PHP in some way

[–] [email protected] 5 points 1 year ago (3 children)

The 80% stem mostly from WordPress and a bunch of domain placeholders.

load more comments (3 replies)
load more comments (1 replies)
[–] [email protected] 14 points 1 year ago (2 children)

Does disappointment count?

After struggling my way through a broken MediaWiki upgrade today, I was reminded once again of just how awful PHP is, both to develop in it and to use applications written in it. What I had to deal with today would not have happened if it were written in a compiled language, because it isn't possible in compiled languages.

Specifically, my MediaWiki settings file contained:

require_once( "$IP/includes/DefaultSettings.php" );

Apparently, this was once required in MediaWiki settings files. After upgrading, though, its presence causes an extremely misleading error message:

Fatal error: Uncaught FatalError: $wgBaseDirectory must not be modified in settings files! Use the MW_INSTALL_PATH environment variable to override the installation root directory. in /path/to/mediawiki/includes/Setup.php:237

My settings file does not contain $wgBaseDirectory. Moreover, adding $wgBaseDirectory = MW_INSTALL_PATH; to my settings file does nothing.

Only after a lot of web searching (and a fair amount of profanity) did I finally find out that the above require_once statement is the culprit.

See the problem here? Interpreted languages like PHP encourage the extremely irritating anti-pattern of using an executable code snippet as a configuration file, which inevitably results in this kind of nonsense. In a compiled language, on the other hand, the easiest way for an application to load settings is by reading them from a data-only format like JSON or TOML, parsers for such formats tend to produce better error messages than this, and the vast majority of such formats don't have an include directive at all.

Had MediaWiki been written in a compiled language instead of PHP, my morning would have been a whole lot less stressful. And this isn't the first time that this configuration-is-code anti-pattern has caused me grief.

[–] [email protected] 7 points 1 year ago

Thank you for taking the time to offer a different opinion to the prevailing sentiment. I am certainly in your camp of being wary of interpreted languages.

[–] [email protected] 4 points 1 year ago (1 children)

It's not just that it's interpreted. I code a lot of Python and I've never just read in another Python file as configuration and executed it. Reading a yaml or json file is like 2-3 lines of code. But I'll bet it's not that simple in PHP.

[–] [email protected] 6 points 1 year ago* (last edited 1 year ago) (2 children)

It is that easy in php:

$jsonConfig = file_get_contents('config.json');
$config = json_decode($jsonConfig);

Β Β 

load more comments (2 replies)
[–] [email protected] 13 points 1 year ago (1 children)

Mature web framework and highly productive language vs less mature framework and emerging language. Personally, I think Rust is the more surprising pick than PHP for this application. A link aggregator is a forum with some frills. Not to mention half of the activitypub implementations that I know of have been in PHP.

[–] [email protected] 4 points 1 year ago

But rust is blazing fast and memory... /meme

[–] [email protected] 12 points 1 year ago (3 children)

Modern PHP is much better than most people expect. It has very little to do with the PHP4 we all grew up to dislike for its quirks and inconsistencies.

That said, I wish more software was done in PHP. And for me it makes a lot of sense regarding the Fediverse. A PHP platform I can put on my existing shared hosting and connect some (sub)domain to it and call it a day. Most smaller/meduim businesses probably have that hosting constellation already around, idling around most of the time. The entry barrier is just so much slower than spinning up a VPS or renting cloud space somewhere just to test a small instance of something. Sure it scales not as good as your average cloudplatform but for most usecases that is not the biggest concern.

Different product but I love Matomo as a Google Analytics because I can just copy the files to a clients shared hosting, connect a subdomain to it and if it uses Sqlite (also better than it's fame!), I am done already and don't need to create a database even.

[–] [email protected] 5 points 1 year ago (2 children)

Massive PHP hater here!

Yeah, even outside the loop I know that, just like every other major programming language, it has grown a lot to mature with general coding practices. It's reasonable well suited for something that has tons of server side content.

load more comments (2 replies)
load more comments (2 replies)
[–] [email protected] 12 points 1 year ago (3 children)

It's not because of word press. Wordpress is complete garbage that should have died ages ago. The reason it hasn't is because it still makes it easy for people to add a customizable site in a couple of minutes.

As for php, the php 5 days are long gone. Php has actually become a good a respectable language since the release of php 7, and things only continue to improve. Php is at version 8.1 and progress is not slowing down. There is even a dedicated full time dev team for php now. PHP is definitely not going anywhere any time soon and I'm more than comfortable with starting new projects using PHP. It happens all the time, especially with support from extremely good and well established frameworks like Laravel.

Honestly if you're starting a new project today, what would be a joke is to start it in node.

load more comments (3 replies)
[–] [email protected] 12 points 1 year ago

There's still lots of active PHP projects, including new ones. PHP is actually a nice language and much of its negative reputation comes from the years of stagnation during the late PHP 5.x era. Which is long over. I definitely find PHP to be much nicer than JS for backend development, although I no longer use it professionally.

[–] [email protected] 11 points 1 year ago

As far as I know PHP is still very active and a great choice for new projects. Lots of new projects get started every day in PHP, the language and tools are still in active development as well as frameworks like Symfony for example.

Sure there's lots of legacy crap including WordPress, but there's also no reason not to use it. Just because people wrote a lot of crappy stuff in PHP doesn't mean it can only be used to make crappy stuff. It's very much possible without a lot of trouble to create solid, good performing, easy to develop and maintain applications in PHP.

[–] [email protected] 11 points 1 year ago (2 children)

It's such an outdated meme to shit on PHP. PHP 8.3 is absolutely nothing like PHP < 5. It's become a full-fledged, performant and secure language. I've been coding PHP since 2005, and I've seen it grow and become incredibly capable. Sure I do recognise that other languages are still more "popular" and respected, and as such I've been focusing more and more on Node/Typescript in recent years, but PHP isn't going anywhere. And its package ecosystem is so much more reliable and stable than say NPM.

load more comments (2 replies)
[–] [email protected] 9 points 1 year ago (2 children)

Same reaction. Rust is the future. Typescript is the present.

[–] treadful 6 points 1 year ago (1 children)

I've done some embedded rust and liked it. I imagine it would be miserable for Web dev though. I haven't checked out what frameworks were around to make things easy so maybe I'm off base. What's the devex like currently?

load more comments (1 replies)
[–] [email protected] 5 points 1 year ago

Lol, this dude literally just pulling feelings out of his ass

[–] [email protected] 8 points 1 year ago (1 children)

Having spent my college years writing dozens of Node apps, when I got a job writing PHP I actually loved it. It was weird at first, the syntax looks old and gross, and it certainly doesn't have the sex-appeal. That being said, I didn't have to spend hours setting up an environment, I didn't have to think much about how to pull in packages, and concurrency via async/await made my life so much easier. The just-copy-everything mentality also meant I could basically never make a mistake ;)

I write C++ (for games) now and often wish things were as easy as when I wrote PHP.

[–] [email protected] 4 points 1 year ago

Ease of use + networked nature was the bane of PHP in term of security. Everyone and their grandma wanted to make a php site but they weren’t exposed to potential vulnerabilities they could make. Which is why php in part has a notoriety to be vulnerable - a lot of people used it, some made mistakes, so there were many vulnerable code bases.

[–] [email protected] 8 points 1 year ago (2 children)

Funny that a lot of people responded by bashing on PHP, but I saw very little real arguments why PHP is so awful. What makes PHP that bad besides being the target of memes?
I mean "lame", "old" or "dead" aren't particularly convincing arguments.

[–] [email protected] 6 points 1 year ago* (last edited 1 year ago) (2 children)

I was fortunate enough to meet Rasmus Lerdorf (PHP founder) long before I became a PHP programmer. At the height of the PHP hate back in the early 00's Rasumus was bravely giving a talk to a group of us stuck up Perl programmers.

To be fair, we had good reason. PHP had borrowed lots of functions from C for familiarity (all those str* functions) and done stupid things that made life unnecessarily difficult, like naming some of them with underscores and others without, and making parameter order inconsistent across similar functions. So it did all these C like things but, it did them way, way slower.

Not only that, PHP also wanted to be like Perl because perl was also a bit like C but did things quickly and parse just about anything you could throw at it. So PHP also shoe-horned in a bunch of regex functions to give perl-like capabilities to their pile of poo. So now it also had perl capabilities, but was performing way, way slower than perl. It was that try-hard kid at school that everyone pretended not to know.

But, on top of it all, Rasmus was very apologetic for what PHP had become. He said to us that PHP was never designed to be a programming language. It was designed to be a "Personal Home Page" templating tool. But soon people wanted to conditionally include bits of templates. Then they wanted to iteratively include bits of template, and then he learned about lex and yacc and rewrote the whole thing and then, one day, there it was. Hideously ugly and Turing complete. And, when he said all this suddenly it all made sense and we had a whole lot of sympathy for where it and he was at. He went on to say that they were putting a lot of working into looking at the worst bits of PHP and making things better. And, credit where credit's due, that''s exactly what he's done. PHP today really is a nice language to work with.

load more comments (2 replies)
[–] [email protected] 4 points 1 year ago (2 children)

It's a terribly designed (and I'm being very generous with the use of the word designed) programming language, but to its defense so is JavaScript and people are not bashing NodeJS apps.

Newer versions of PHP seem to be dealing with lots of past mistakes, but it will always have lots of warts due to backwards compatibility.

load more comments (2 replies)
[–] [email protected] 7 points 1 year ago (1 children)

more so surprised that it wasn't written in {insert favourite language here}

that being said I agree that PHP isn't anything like it used to be.

load more comments (1 replies)
[–] [email protected] 7 points 1 year ago

PHP is not as shitty as it used to be. Additionally, it's very approachable and it runs basicly everywhere.

[–] [email protected] 7 points 1 year ago (2 children)

It's written using Symphony framework and seems to be using the latest best practice. Nothing to worry about here. PHP has its warts, which are being addressed since PHP 7.x. Modern frameworks like Symphony go even further by encouraging best practices when developing PHP WebApps, unlike the dark old days of PHP WebApps full of SQL injections and XSS issues (still is though in the WordPress plugins ecosystem).

I'm mostly a Python guy and used to look down on PHP, but changed my tune since the release of PHP 7.x. If Python has JIT half as good as PHP these days, I would die happy.

load more comments (2 replies)
[–] [email protected] 6 points 1 year ago

PHP lost a lot of popularity yes. But developers still use the major PHP frameworks, those solve a lot of the issues many developers had with PHP. On the StackOverflow survey Laravel was still used by 7.5% of the responses and Symfony by 3.2%.

Currently I’m actually taking over a website that was written with Laravel and rebuilding everything in SvelteKit.

[–] [email protected] 5 points 1 year ago (1 children)

Not too surprised. I know PHP has a reputation these days of being old and crufty but at the same time there hasn't really been a killer replacement yet for the same use cases where PHP is/was used. React and Vue are all the rage for frontend work, but their paradigm is all about single page apps which is a bit limiting for something on the scale of Kbin. Other backend frameworks like Django tend to be fairly opinionated and lock you into developing in a certain way without providing a large enough benefit to make it worth it.

IDK maybe there are better frameworks that I just haven't heard of. But whenever I go to start personal projects, the options seem to be Express, Flask, or PHP, all of which have their own tradeoffs. Personally I lean more towards Express or Flask but it's not surprising to see people stick with PHP.

load more comments (1 replies)
[–] [email protected] 5 points 1 year ago

Nowadays is only a matter of community and resources related to the language that one can find online. Php lost popularity and gained this image as a bad language, this brings a lot of devs to not use Php without a real factual reason. Is just not cool or they feel ashamed to tell that they work with Php.

If a dev works with typescript is more easy to find a lot of cool and pleasing resources, videos, articles. With php, for the reasons explained above, the stuff you can find it does not feel so cool as other mainstream languages. And here the game start over, for this reason less people use it and so on. This give to the entire php ecosystem a kind of "old" feeling and a lot of young devs just don't like it.

But rarely there are real reasons. With php 8 for sure there are not a lot of reasons to blame the language to be a bad language.

Until a couple of years ago I used to work with the last versions of php and I actually never felt the urges to redactor everything in some other language.

I am sure that php has limits, but in the same way as all other languages have their limits: they are just tools at the end.

Stop blaming php. Blame WordPress instead! :D

But I would ask he opposite question: can somebody make an argument to not use php? From a dev point of view.

[–] [email protected] 5 points 1 year ago (2 children)

Large parts of my particular departments .gov.uk stack are PHP. All modern (8.1+) using established frameworks and to be honest, it's a joy. It's quick to write, easy to understand and very easy to test. The write, run, debug cycle is also essentially instant; although I really enjoy using Go (another bit of the stack) being able to quickly iterate changes is something I absolutely miss when I'm using it.

Laravel + Livewire is some sort of dark voodoo magic. I can write only PHP and have a functioning SPA with push updates and all sorts.

load more comments (2 replies)
[–] [email protected] 3 points 1 year ago

I joke about PHP being a dead language a lot but AFAIK modern time PHP is actually a pretty decent language. Haven't coded one tho personally.

[–] [email protected] 3 points 1 year ago (1 children)

Modern PHP is supposedly pretty alright but yes I was surprised and a bit disappointed, I would have liked to contribute but I'm not gonna touch PHP in my free time lol.

[–] [email protected] 2 points 1 year ago

This is similar to how I feel.

PHP is pain to developers Jerry!

[–] [email protected] 3 points 1 year ago* (last edited 1 year ago)

In my opinion, only the most elite (in all the wrong ways) people care how you build your app.

PHP has flaws, sure[1]. But unless you are working on the app itself (or again, you are horribly elitist) it does not matter.

What matters is that the app is good. If the app is good, it doesn't matter that its done in PHP, what matters is that it works.

EDIT: I guess it also matters if you're selfhosting the app.

[1] I think PHP is overhated. As a stateless language it lacks a lot of complex features (and thus, admittedly, might be questionable for a project as large and complex as kbin), it has some questionable design decisions, but it's really not as bad as people make it out to be.

[–] [email protected] 2 points 1 year ago (1 children)

Modern PHP is quite performant and nice to work with and it's still improving! Also frameworks like Laravel is very established.

When comparing the time when I use PHP and JavaScript, I love the simplicity and versatility of JavaScript but PHP's strongly typed (with runtime support) and object oriented language often make more sense imo.

I think the strong benefit of using JavaScript for backend comes down to being able to have unified full-stack codebases, one language fits all kind of thing.

load more comments (1 replies)
load more comments
view more: next β€Ί