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?

  • argv_minus_one@beehaw.org
    link
    fedilink
    arrow-up
    13
    ·
    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
            5
            ·
            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.