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?

  • Cade@beehaw.org
    link
    fedilink
    arrow-up
    19
    ·
    1 year ago

    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.

    • Jdreben@beehaw.org
      link
      fedilink
      arrow-up
      8
      ·
      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

  • argv_minus_one@beehaw.org
    link
    fedilink
    arrow-up
    16
    ·
    1 year ago

    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.

    • WatTyler@lemmy.sdf.orgOP
      link
      fedilink
      arrow-up
      6
      ·
      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.

    • tias@discuss.tchncs.de
      link
      fedilink
      arrow-up
      4
      ·
      1 year ago

      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.

      • l3mming@lemmy.fmhy.ml
        link
        fedilink
        arrow-up
        6
        ·
        edit-2
        1 year ago

        It is that easy in php:

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

        • tias@discuss.tchncs.de
          link
          fedilink
          arrow-up
          2
          ·
          1 year ago

          Well in that case, it’s just bad coding.

          I guess there’s a tendency for interpreted languages to attract more bad coders because trial & error is easier and you can get started in fewer steps. Also, fewer confusing compiler errors to deal with.

          • PJB@lemmy.spacestation14.com
            link
            fedilink
            English
            arrow-up
            3
            ·
            1 year ago

            To be honest, the “configuration is an executed .php file” system does make some amount of sense in the context of PHP. When your app has to re-run everything to serve a web request, having to re-load the config (especially if it’s YAML, though JSON is less bad) is expensive. Re-running the PHP code, on the other hand, can be cached way better, in theory.

            Of course, this is still all PHP’s fault in the end: the core problem here is that you need to re-run everything to serve a web request, without ability to pre-load state like configuration.

  • l3mming@lemmy.fmhy.ml
    link
    fedilink
    arrow-up
    14
    ·
    1 year ago

    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.

    • WatTyler@lemmy.sdf.orgOP
      link
      fedilink
      arrow-up
      2
      ·
      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.

    • tal@kbin.social
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      I don’t really focus on Web development (though I’ve done a little in various languages when it became necessary to solve specific problems), but over the years, for software development, I’ve become pretty conservative about adopting new programming languages, frameworks, libraries, and so forth when they come out. I have seen a very large number of things that were new and trendy vanish in the wind after people put a lot of effort into coming up to speed on them.

      Once there’s a large installed base, though, they’re gonna be around for a long time to come, because software projects have committed to them.

      None of this is to ding Rust, which Lemmy uses. I’ve never written a line of Rust myself, don’t know the ecosystem. But I don’t think that PHP is bad just because it’s pretty mature.

      Also, related side note: Reddit was originally implemented in some Lisp variant, probably in part because Paul Graham, who was involved in some early funding, is a huge Lisp fan. There isn’t that much web dev happening in Lisp, and Team Reddit later had to go back and reimplement it in the more-widely-used Python, on the Pylons framework. That doubtless cost them a lot of dev time.

      • Thorry84@feddit.nl
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        Totally agree, people seem to be always searching for the next hot thing, claim it’s better than everything else and start porting stuff to it. A couple of years later they choose the next hot new thing and ported their old stuff over to that. And so the cycle continues.

      • Bipta@kbin.social
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        PHP isn’t bad because it’s mature. It’s bad because it’s PHP.

        Still, it’s good for the right jobs.

    • scarcer@kbin.social
      link
      fedilink
      arrow-up
      0
      ·
      1 year ago

      While I haven’t tried symphony, my annoyance with PHP in general is that parsing any kind of data is tacky. In the end you have just as many lines as python but less readable.

      Cleaner functions or cleaner data? Both languages have their strengths and can (now) be typed.

      • l3mming@lemmy.fmhy.ml
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        Well, this is true. It’s all about the right tool for the job. The PHP hammer is good at some things and bad at others. It is good for web development, it is bad for parsing [thanks to its truly awful regex functions], and it is way too bloated to be any kind of scripting language. Python is much better for parsing and transforming data, but its regex implementations are still pretty awful when compared to something like Perl. In fact, I still reach for Perl when I have to parse complex and unstructured text. Haven’t yet reached for Perl 6 though.

  • hadesflames@vlemmy.net
    link
    fedilink
    arrow-up
    13
    ·
    1 year ago

    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.

    • worfamerryman@beehaw.org
      link
      fedilink
      arrow-up
      3
      ·
      1 year ago

      I’m trying to get a website up and running, but I need to be able to self host it. Can your recommend something other than Wordpress that I don’t have to code?

      Eventually I’ll have something cussing made, but for the time being, I just need something up and running.

      • GiganticPrawn@beehaw.org
        link
        fedilink
        arrow-up
        3
        ·
        1 year ago

        Not sure if you’re familiar with the terminology but WordPress is a Content Management System (CMS). I honestly don’t know of many other than WordPress, I’ve heard of Joomla and Drupal but can’t speak to anything about them other than they’re CMSs, they’re FOSS, and I’ve heard them talked about.

  • ferm@beehaw.org
    link
    fedilink
    arrow-up
    8
    ·
    1 year ago

    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.

    • Hexorg@beehaw.orgM
      link
      fedilink
      arrow-up
      4
      ·
      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.

  • redcalcium@c.calciumlabs.com
    link
    fedilink
    arrow-up
    8
    ·
    1 year ago

    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.

    • balls_expert@lemmy.blahaj.zone
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      1 year ago

      There’s still lots of problems with php like the type system exists now, but doesn’t let you put types on containers (arrays, hashmaps etc) so you still can’t use the type system to model your app in a way that invalid states throw compiler errors. And it’s certainly not ever going to be an algebraic type system. Nothing past the basics make it into php.

      They’re trailing behind in every way. Have you ever looked at a php feature and went “oh god, I want that!”?

      • redcalcium@c.calciumlabs.com
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        I don’t use PHP enough to comment about its type system, but at the very least it’s no longer a horrible language anymore. If for some reason you are forced to use PHP to greenfield a new project, at least you don’t have to worry too much about basic stuff anymore.

        If there is one PHP feature I absolutely want, it’s the blazing fast JIT which put other interpreted languages to shame.

  • leetnewb@beehaw.org
    link
    fedilink
    arrow-up
    7
    ·
    1 year ago

    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.

    • treadful@lemmy.zip
      link
      fedilink
      arrow-up
      7
      ·
      1 year ago

      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?

  • 0xCAFe@feddit.de
    link
    fedilink
    arrow-up
    5
    ·
    1 year ago

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

  • hyperlink2236@feddit.it
    link
    fedilink
    arrow-up
    5
    ·
    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.

  • Rekkar@feddit.de
    link
    fedilink
    arrow-up
    4
    ·
    1 year ago

    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.

    • Deedasmi@lemmy.timdn.com
      link
      fedilink
      arrow-up
      2
      ·
      1 year ago

      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.

      • catacomb@beehaw.org
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        I went from PHP lover to PHP hater about a decade ago. I have to admit, reading some of the Kbin code has made me hate it a little less. It’s nice not to see include() and require() everywhere. It’s also nice to see some type safety features as that was the biggest reason I moved on. For anything much bigger than a simple script, even if you think you won’t, you’re going to struggle without it.

        It’s still not my first preference (and, let’s face it, most of this is preference) but it looks a lot better.

      • Rekkar@feddit.de
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        Kudos for saying that even as a massive PHP hater :)

        IMO there is a reason why Wordpress is so popular (Disclaimer: massive Wordpress hater here!). Because of ease of install, more people can upload some folder in an (Web)FTP client than spinning up a Docker Container somewhere to host the latest JS Framework of the day just to host their little page or to show their content.

        There is simply no need for bundlers, preprocessors and often not even [a lot of] package management (I’m aware of PHP composer though)

        And exactly that ease of install is what could IMO make the Fediverse more democratic than having to run a container at some VPS that only a comparetively few people are able to do.

    • redcalcium@c.calciumlabs.com
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      It’s not an issue these days now that containerized deployments became mainstream. As long as your project provides a Dockerfile, nobody cares what language and framework you use as you can deploy a docker image almost everywhere these days. Both Lemmy and Kbin includes a Dockerfile out of the box.

      • Rekkar@feddit.de
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        You are right that there is a dockerfile for pretty much everything these days.

        However, as an example, I am using Sabre as a CardDAV/CalDAV Server on one of my domains. There is simply no need to spin up an extra container for something simple like this. Same with Matomo for analytics in my comment above, you are just writing a better logfile essentially.

        Now Kbin has much more functions than that and I would probably run that in a container as well. For smaller and leaner things, I see shared hosting still as the easier way. When you know that containers exist, you are already in an expert bubble. I would claim that many many people know how to use an FTP client from their Desktop than are able to host a container somewhere - not that I’m a fan of FTP but SCP is already more advanced for that said group I assume.

    • ursakhiin@beehaw.org
      link
      fedilink
      arrow-up
      2
      ·
      1 year ago

      I don’t hate PHP, but I am wary of developers who only work in it. For the same reason I’m wary of Java developers, though.

      A language is a tool and should be treated as such. Trying to force every problem into a single box is skin to the “everything is a nail” idea.

      That said, I’m not sure Rust was the right call for the Lemmy backend, either. I like Rust. My team is transitioning to it for a system level service. But we would have chosen a different language if our goal was a web backend.

      The thing with open source projects, though, is often times they are written in the language the developer is learning or working in at the time, not because the language is the most suited for the job.

  • artillect@kbin.social
    link
    fedilink
    arrow-up
    4
    ·
    edit-2
    1 year ago

    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

      • YMS@kbin.social
        link
        fedilink
        arrow-up
        3
        ·
        1 year ago

        WordPress, Joomla, Typo3, Drupal, … PHP is pretty much omnipresent in CMS systems. It’s not a huge number of different PHP CMS, but it results in a huge number of websites being PHP-based. The vast majority of those websites don’t care for the programming language - they pick an existing CMS so they don’t have to do their own programming.

      • ipkpjersi@lemmy.one
        link
        fedilink
        arrow-up
        2
        ·
        1 year ago

        Sure but there’s also Pornhub, Wikipedia, and Facebook which use PHP. Other large websites use PHP too.

  • gus@beehaw.org
    link
    fedilink
    arrow-up
    4
    ·
    1 year ago

    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.