My PHP Problems

111 points by gempir 1 year ago | 152 comments
  • hiAndrewQuinn 1 year ago
    I finally had a chance to write some PHP that (a) wasn't WordPress and (b) actually did something useful a few weeks ago at $DAYJOB.

    Going from zero to functional web backend in less than 3 hours for a language I'm almost totally unfamiliar with made me understand just why this got so gosh darn popular. I thought building out a Flask application was fast, but PHP's initial experimentation loop is just on another level, criticisms be what they may.

    • ChrisMarshallNY 1 year ago
      I've been writing PHP for a quarter century, but I've never become a "whiz" at it.

      But I regularly write fast, robust, secure backends, in a day or less (less, if possible. I don't actually like working in PHP).

      Despite the torrents of hate from this community, it is still pretty much the backend king.

      Here's the "Fishtank Graph."[0] It kind of puts things in perspective.

      [0] https://w3techs.com/technologies/history_overview/programmin...

      • netule 1 year ago
        I agree that it still owns a massive chunk of the backend market. 20-something years in, and it's still difficult to shake.

        However, I would take the numbers on the site you linked with a big grain of salt. Detecting which backend technology powers a site without direct evidence is nearly impossible. PHP may be high up the list since it and its associated stack leak the most metadata.

        • stevarino 1 year ago
          I've totally copied php http headers into non-php backends just to see what happens. It costs nothing and gets a trifle more security.

          (Not really but it makes me giggle at least)

          • 1 year ago
          • KronisLV 1 year ago
            I've always found those statistics to be a bit odd, given how popular other languages are, especially the likes of Python.

            Not only that, but since .NET Core and the new versions of .NET running just fine on Linux distros, I'd expect their usage to go up, not down.

            Curious. Actually, their disclaimer page seems to suggest that setups with a decoupled SPA/API might not be detected correctly: https://w3techs.com/disclaimer

            • mp05 1 year ago
              > the likes of Python

              I've spent 15 years writing serious code and never ran into Python all that much until I went back to engineering school. I don't think a lot of people use it for their backend code, at least in my experience. But wow are there lots of stats and science people using it exclusively--it's completely ubiquitous in academia and research (though R is making headway).

              • MrVandemar 1 year ago
                > I've always found those statistics to be a bit odd, given how popular other languages are, especially the likes of Python.

                Think about how many Wordpress installs there are, not to mention Wiki's and forums.

                • throwaway84862 1 year ago
                  At my previous job, we had micro services in Java that did most of the work. The frontend was a thin layer of PHP that focused on SSR, but PHP is the only detectable tech from the outside
                • jimbokun 1 year ago
                  Surprised to see Scala running almost as many website backends as JavaScript. In my mind, it faded in popularity long ago.
                  • brlewis 1 year ago
                    The survey methodology is biased toward old technologies, from the era where you sent HTTP headers that advertised the stack you were using. Modern stacks often hide that info. (It's also biased toward techs used in blogs, since when it detects a tech used on blog.example.com, that tech is counted for example.com)
                    • mp05 1 year ago
                      Perhaps the Scala ecosystem is where Haskell nerds all decided to settle into?
                  • dijit 1 year ago
                    I upvoted you and vouched u/rizky05 because I think they raised an important point.

                    > It is powerful indeed. But PHP syntax feels unelegant and making me write unnecessary ceremony. It feels different when I write typescript code, every character I type fits like lego.

                    > Especially when my codebase grows so much. Navigating PHP project is like thrown in forest without a map, you can always look up the sun to find your way.

                    “Elegance” is something that gives people warm fuzzies, I think this is why there are so many Rust advocates (I am one), when pieces fit together nice or can be refactored cleanly and tests are first-party it is nice.

                    However there have always been “hacky” and “proper” languages, because doing something hacky that works also feels great.

                    Python is a hacky language, it’s easy to go to 0-100 very quickly. C++ however requires time and precision to make things proper, so people avoid it and few things are made comparatively in C++ unless it's infrastructure software that people spent a lot of time writing.

                    Maintainability be damned, sometimes you really just need to throw something together.

                    The curse of things that work is that they will be expanded upon and kept around for too long.

                    Unfortunately: PHP works, and is an excellent hack-language for the web. Which means there’s a lot of code that becomes “production grade” that should really have never been intended to live forever in the first place.

                    • thinkindie 1 year ago
                      PHP can be super hacky and super structured, within the same file, and it's your choice. You can have tests, static analysis, etc etc, or not. Or you can start without and then adding it as the project mature, without having to necessarily switch to another language.

                      I'm working on my own startup that started as a side project and it was super hacky at the beginning, but by sticking to PHP (and thanks to PHP continuous improvements) I was able to refactor little by little and make the codebase way more structured and easier to maintain.

                      • Shish2k 1 year ago
                        As a vaguely-related anecdote, I wrote a super-hacky PHP script in highschool 20 years ago, it gained some popularity based on being open-source and easy-to-install (PHP’s #1 strength for sure) - and to this day I am still spending a significant chunk of development time refactoring based on ideas that eg Typescript and Rust have out of the box (eg using PHPStan to emulate a language with typed arrays)

                        (I keep wishing that I could rewrite it in a “better” language, but there is no other language that is even in the same ballpark when it comes to “any random user can upload this .php file to any random web host and expect it to work”)

                        • lmm 1 year ago
                          You can write any kind of code in any language, but going against the grain of that language tends to go badly. Even if your style works for you, if it's not what the ecosystem expects you'll have trouble using libraries, you'll have trouble onboarding new hires, ....
                          • mp05 1 year ago
                            Zuck wrote a super hacky PHP script 20+ years ago and now he's a gazillionaire.
                          • smarkov 1 year ago
                            > when pieces fit together nice or can be refactored cleanly

                            This is a trade-off that makes sense to embrace in some contexts, and I do believe that web is one of them. The more nicely your pieces fit together the harder it'll be to break them apart. You can only refactor cleanly once you are aware of all the requirements, but those requirements are usually constantly changing in the context of web and so your pieces fitting together a little too nicely means that you now have to refactor a lot more code.

                          • penteract 1 year ago
                            This matches my experience of PHP. The questions/advice on stackoverflow and blog posts are also geared towards people who just want to get something done, which helps a lot if that's your goal.

                            Go is the only other programming language I've had this experience with - picking it up with a goal in mind and succeeding in doing something more quickly than I might have with a familiar language.

                            • hiAndrewQuinn 1 year ago
                              I remember someone on SO saying "Go isn't a programming language, it's a DSL for writing networked services", and, well, if we can squint and call Go that, we can definitely call PHP a DSL for dynamic webpages.
                              • nucleardog 1 year ago
                                You don’t even really need to squint that hard.

                                That’s what it started as.

                                It’s entire process model (instantiating the world for each request then tearing it all back down, not having any shared state) is fairly unlike most other general purpose languages.

                                PHP inverts the usual assumption that “this code file is primarily code” on its head—it assumes any file it’s given contains other data until it finds the special open/close tags signifying a section that contains code. (Allowing you to embed it within HTML easily.)

                                The runtime handles things like GET/POST variables natively and has a special way to expose them. Ditto for file uploads.

                                The standard library isn’t extensive but contains a ton of functionality that revolves around managing web requests. (Managing HTTP headers, setting and reading cookies, ...)

                                Etc, etc.

                              • jimbokun 1 year ago
                                I’ve been using Go in this capacity quite a lot recently, replacing Java code I had previously been using for these kinds of tasks. And have been pleasantly surprised how straightforward the code is.

                                Especially now with generics support. I’ve been able to quickly write little meta functions for things like translating Kafka events to a channel of structure and spin up a number of go routines to handle them by making REST calls. The code is concise, clean, and simple, without being overly clever.

                              • kingofthehill98 1 year ago
                                It's such a perfect match for the HTTP protocol. You drop a file on a server and you're good to go. My toy VPS is full of useful scripts that I use on a daily basis. Most of them are literally one big file with all of the code, no external dependencies. Caddy proxy the request into PHP-FPM and send back the response, no bullshit.

                                Of course this is not what we see at production-grade software, but I really enjoy the fact that the language was designed with the HTTP protocol in mind. It's really unique in this sense.

                                • jdpedrie 1 year ago
                                  On the other hand, vanilla PHP effectively "hides" HTTP from the programmer. I taught myself PHP in middle school and high school as my first programming experience, and had no concept of a thing called "HTTP" for a very very long time. I knew the pieces of it that PHP gave me. I knew what $_POST, $_GET, $_SERVER, $_HEADER, set/getcookie(), were and how to manipulate them, and I knew the rules (setting a header after "echo" made it complain), but I didn't understand how that all hung together as a thing outside PHP called HTTP.

                                  When I did learn about HTTP, it was very easy, since I already knew it without knowing I knew it, so maybe that's in favor of your point, but there's much to be said for the actual understanding that I didn't have at first. When I started interviewing people for PHP entry-level jobs, asking about HTTP was one of the ways I gauged how well applicants understood their work at a conceptual level.

                                  • fideloper 1 year ago
                                    This mirrors my experience exactly - it took me an embarrassingly long time to learn about http and what it means to be stateless.

                                    It also took learning other languages to understand how PHP is so unique in how tied to HTTP it is (rebuilding its entire universe every request).

                                    (these learnings happened when moving beyond the PHP-based CMS style of development - agency style work on my case - to make more custom software).

                                  • tsukurimashou 1 year ago
                                    yes, and the fact that you can just put inline HTML outside of PHP tags is so useful and convenient
                                    • zer00eyz 1 year ago
                                      LOL

                                      The fact that I can't tell if this comment is sarcasm or snark or serious says a lot.

                                      PHP mixed with HTML was one of the "bad ideas" that hurt PHP. It was a bad practice that got out of hand.

                                      Now why no one bats an eye at node/react doing this very thing and calling it JSX is beyond me but...

                                  • indigodaddy 1 year ago
                                    Any online resources you used to get yourself on the right track or as a starting point to get running?
                                  • evantbyrne 1 year ago
                                    In a lot of ways, PHP represents developer productivity maximalism. It's neither pretty nor safe, but there is a lot that other communities could learn by studying popular PHP libraries.
                                    • rizky05 1 year ago
                                      It is powerful indeed. But PHP syntax feels unelegant and making me write unnecessary ceremony. It feels different when I write typescript code, every character I type fits like lego.

                                      Especially when my codebase grows so much. Navigating PHP project is like thrown in forest without a map, you can always look up the sun to find your way.

                                    • kingofthehill98 1 year ago
                                      Loved this article, those were all great points that I have faced on my daily job at a PHP shop.

                                      A breath of fresh air in amids of thousands of "ew, such a bad language" and "a fractal of bad design", the latter being incredibly outdated and still referenced from time to time.

                                      I love PHP, it was my first language and it's one hell of a productive ecosystem to be in. Laravel is an excellent choice for rapid prototyping and Symfony is probably one of the best web frameworks for enterprise projects. Paired with coroutines extensions such as Swoole/OpenSwoole/Swow it puts one hell of a fight performance wise with more modern languages.

                                      • begueradj 1 year ago
                                        I agree. Also Laravel is one of the best web frameworks for rapid prototyping :)
                                        • bemusedthrow75 1 year ago
                                          Indeed.

                                          Also, I have been looking for GraphQL implementations for other server-side languages recently and I have yet to encounter a schema-first implementation that comes close to what the Lighthouse layer for Laravel can do.

                                          That is really productive.

                                          • withinboredom 1 year ago
                                            Why would you want to use graphql? In my experience, it’s pretty terrible for real-world use-cases.
                                            • aglione 1 year ago
                                              have a look to http://strawberry.rocks for Python.

                                              I've still to find a better code first implementation too

                                          • viraptor 1 year ago
                                            Huh? This article is talking about very similar issue to the fractal of bad design. Down to repeating specific ones like json_decode(null). Most of the fractal post still applies. The themes of surprises and consistency are strong in both.

                                            I agree that the language evolved since then, but the main categories are still not solved in the language. Nice frameworks just hide those well.

                                            • bemusedthrow75 1 year ago
                                              The thing that I think PHP developers hate most about the Fractal of Bad Design article is hearing it from full-stack JS developers. They really do not have the moral high ground.

                                              PHP has improved since in a way that is rarely considered when reposting it, but JS has some deep language horrors of its own still, and many novel JS horrors like NPM have emerged largely since the Fractal article was published.

                                              As the King sang, so eloquently: o/~ clean up your own backyard o/~

                                              • crabmusket 1 year ago
                                                As someone who writes PHP and JS professionally every day, I think they're leagues apart.* Sure, people love to look down on JS, but its fundamentals are much stronger than PHP's.

                                                PHP is no longer a terrible language- recent editions have made leaps and bounds on language features, and the ecosystem around Symfony is great. But on a weekly or monthly basis I run into something that makes me want to head-desk.

                                                JS's recent(ish) language improvements like `let` and ESM have been much more fundamentally significant than PHP's IMO, where we're still stuck with bad scoping and Java-brained class autoloading.

                                                *Not leagues apart in terms of productivity. I can certainly get a lot done with PHP. I mean leagues apart at their foundation, the basic concepts at work in the language. Most of that can be ignored until it rears up to harass you. Here's a great example of something similar to an issue that bit me last month:

                                                https://stackoverflow.com/q/3307409

                                              • yurishimo 1 year ago
                                                In php 8.3, there is a new json_validate function! Stuff changes, it just takes a bit of time. Luckily, the core maintainers have been putting out steady releases every year and old versions are being deprecated on a rolling 3 year cycle. It doesn't solve the historical problem, but hopefully it enforces better habits for the ecosystem moving forward.
                                                • otabdeveloper4 1 year ago
                                                  Nitpicking on trivialities is pointless.

                                                  Rather, point out the fact that Symfony is a framework that relies entirely on all sorts of magic behavior, and at the same time it is entirely undocumented.

                                                  One of the most horrible programming experiences I've ever experienced.

                                                  PHP is a nice language, but the community is insane.

                                                  • kingofthehill98 1 year ago
                                                    Just out of curiosity, when was the last time you worked with Symfony?

                                                    The framework has changed massively after the earliest versions (1~3). These days it's very similar to Java's SpringBoot. After scaffolding all you get is a thin layer with the HTTP abstraction, configuration support, reflection-based Dependency Injection and a testing framework (PHPUnit).

                                                    Since the framework is component-based you pull dependencies as you need them. I find the documentation really good and honestly I don't see much magic in it, it's an event-based web framework. Laravel and it's facades on the other hand is very magical.

                                                    • conradfr 1 year ago
                                                      It is actually documented, surely you must be confused?

                                                      You have the docs with extensive examples, you have a free book, and the whole framework is typed and all configuration options and the individual components referenced: https://symfony.com/doc/current/index.html

                                                      And if you use PhpStorm with the Symfony plugin almost everything gets intellisense.

                                                    • kingofthehill98 1 year ago
                                                      Honestly I don't see it that way.

                                                      The blog author makes solid points that I agree. Meanwhile AFOBD just make fun of stdlib inconsistencies and of language quirks, most of which were fixed throughout the years.

                                                      AFOBD is so incredibly outdated that this paragraph is still there: "PHP is naturally tied to Apache. Running it separately, or with any other webserver, requires just as much mucking around (possibly more) as deploying any other language.".

                                                      • zanellato19 1 year ago
                                                        Some of the points are outdated, but the soul of the article, that those stdlib inconsistencies and language quirks as you called it, lead to terrible design and a lot of surprising footguns, is still quite true. Laravel is a good framework and it is because it hides a lot of PHP from the user.
                                                  • fHr 1 year ago
                                                    I see the advancements in php and I think I could go back by now but I know that 90% of comapnies recruit you to fix some wordpress 4/php 5 bugy and custom plugin infested site that should just be made from scratch but because there is no money and "just quickly fix it in 1 workday" gives me php ptsd once again.
                                                    • bemusedthrow75 1 year ago
                                                      This is absolutely a problem.

                                                      It's now a powerful, fast, flexible platform with a load of amazing libraries and tools -- graphql, webhooks, databases, all sorts. There's an amazing level of recent PHP support out there you can host on.

                                                      And then there are the terrible applications, written from inadequate specs, in a hurry, by people who just aren't developers. And they are embedded, and people want them fixed.

                                                      You have to have a knack for, and some enjoyment from, that work.

                                                      The worst I have encountered is a Wordpress site built by some people who did not know Wordpress could do several important things, so they'd subverted the loop, ignored where they could hook, and embedded wordpress outside the loop to do stuff, which was a nightmare.

                                                      The second worst was, it must be said, a Laravel app, but that problem wasn't the PHP so much (though it had been written in a hurry with an awful lot of duplication that we could have refactored out), it was the unreliable assumptions made about MySQL default result ordering.

                                                      Which is actually the secondary problem here: people who make bad PHP decisions usually make bad SQL, email and HTTP decisions too.

                                                      If building your own thing from scratch, or starting a new project, etc., PHP is a blast now, actually. But the very old things... not so much.

                                                      • zerocrates 1 year ago
                                                        Yes, back in the "old days" of PHP you could ignore ordering and grouping on MySQL and it would pretty reliably give you back things in a stable "order of insertion" order where there was ambiguity.

                                                        Of course that was never guaranteed and subsequent optimizations and changes have really removed that ability to ignore order in many situations. Plus, MySQL also changed to actually check if you're doing GROUP BY properly by default.

                                                        MySQL was always a big part of the PHP story so it's fitting they've followed similar arcs of improvement and growing pains over the years.

                                                      • hiAndrewQuinn 1 year ago
                                                        PHP is probably like Excel, in that is is really helpful from a raw productivity standpoint to be good at it, but you really don't want other people to know that you're good at it.
                                                        • mschuster91 1 year ago
                                                          IME, that also makes PHP worth it for shell scripts. It's miles better than the common baseline that's bash/perl... but once word gets out, people will ask you to rewrite their 30 kLOC sh monstrum into something readable...
                                                          • bemusedthrow75 1 year ago
                                                            Mmm. It really depends on whether you have the scope to start your projects and stay in control.
                                                            • naranha 1 year ago
                                                              idk, when I want productivity I go with nodejs these days. lodash for some quick data crunching and pg or mariadb for db access using promises simply beats native php functions. with express you can spawn a http server in under 10 lines, while with php you need to setup apache/nginx or docker.

                                                              at some point in the past PHP was the most productive tool for some quick & dirty coding, but not anymore for me.

                                                              • withinboredom 1 year ago
                                                                I recommend checking out FrankenPHP, where you can spin up a production php server with a single cli command, or compile your php into a self-executable binary.

                                                                I’m a contributor over there.

                                                            • cardanome 1 year ago
                                                              Not my experience. You will see some legacy code but that is to be expected in any coding job.

                                                              Wordpress is kind of it's own ecosystem. I have been a PHP dev for years and never touched any Wordpress code.

                                                              Most jobs recruit for specific frameworks like symfony or laravel.

                                                            • endofreach 1 year ago
                                                              I might be a minority, but i truly enjoy PHPs syntax a lot. No other language i use gives me the same joy.

                                                              Modern PHP is great, the past & some fundamental decisions are automatic tech debt that i can live with. It'd be great if PHP 8.3 gets forked with no backward compatibility, removing all the old PHP as a template engine designed functions that nobody needs & release under a new name. I just can't find the same type of joy in writing code as i do when writing PHP. But some things are truly annoying. Just not enough for me to switch or start the fork myself.

                                                              • chuckadams 1 year ago
                                                                On a few occasions I've done a few weeks of refactoring the php source toward creating just such a fork, but decided it was just going to be too much work over time for too little benefit for too few people. And that's true of pretty much all "legacy-free" forks: it's fun to rip out all the legacy crap, but you're left with an incompatible language in the end, at which point you're probably better off starting with a different language entirely.
                                                                • endofreach 1 year ago
                                                                  Anything of your refactorings public to check out?

                                                                  > but you're left with an incompatible language in the end, at which point you're probably better off starting with a different language entirely.

                                                                  Yes, but which one?

                                                                  No matter which one i try, in the end, i am always close to rewriting it with php. Eg as many good things go has, i don't enjoy the syntax as much as phps. I could live with it, given the advantages. But i can't get over it, that most of my code seems to be error checking. Sure, that's probably a good thing for serious work. But that's just not where the joy in programming lies for me. Most cases phps try-catch feels much, much more elegant / fun to write (not comparing the efficiency of the outcome).

                                                                  I do love the fact i end up with a single executable. And php without framework requires much more overhead, which is also annoying. And i am done with php frameworks.

                                                                  • chuckadams 1 year ago
                                                                    I'm afraid I burned it down to the ground, but the last attempt never got me much past reorganizing the headers and ripping out ifdefs for all non-posix systems (bye bye windows support). These days I'm interested in more green-field languages like unison, though I'm still trying to think of something to write in it (or any inspiring language, really).
                                                              • esquire_900 1 year ago
                                                                This is a bit too much of an apples vs oranges. Use cases for PHP (easy to develop, maintain websites) are different from those for Go and Rust.

                                                                Obviously, PHP came from a place of great inconsistency, and the remains are still there, including the popularity to rant on it. PHP is getting significantly better though, and while a long one, I hugely prefer this route over something more abrupt like python 2-3. The first 3 or so points are valid, but annoyances at best. For the points about closures, statements, inline classes etc., they are just features from other languages that aren't in PHP.

                                                                • amne 1 year ago
                                                                  I can't for async/await to reach PHP and see code that awaits 5 queries and 3 http requests in a row. Perfection.
                                                                  • woutersf 1 year ago
                                                                    This sentence does not make sense and still I understood it perfectly. It's the reason I love PHP over JS.
                                                                • zer00eyz 1 year ago
                                                                  PHP buttered my bread for over a decade. I bear it no ill will, and this article was a lot of nostalgia.

                                                                  The "living on a prayer" comment on serialization brought back memories. It made me acutely aware that I use this pattern in go, and there it "just works". I now have a note to go see what Valinor, PHPStan, Psalm, Serde are because they sound godlike.

                                                                  • bandrami 1 year ago
                                                                    I still have contracts in Cold Fusion. PHP is not remotely the worst web templating language out there in active use...
                                                                    • lsaferite 1 year ago
                                                                      I lasted about a month working on a CF ecomm website many years ago. I've refused to even approach CF since then. More power to you. :)
                                                                      • djbusby 1 year ago
                                                                        Hello from maintaining ASP3.0 "apps".
                                                                      • sourcecodeplz 1 year ago
                                                                        Good for PHP that it's getting more and more traction (attention) lately. Bad press is still press & PHP is quite not bad nowadays, when you start from scratch.
                                                                        • pastureofplenty 1 year ago
                                                                          I've been working with PHP for the last couple months or so for the first time in over a decade. I can't say I've enjoyed it. Feels very tedious always having to look up, say, whether the needle comes first or the haystack in a list of arguments. But it runs pretty darn fast, I'll give it that.
                                                                          • djbusby 1 year ago
                                                                            Many editors have tools that show language functions and their parameters as you type, so you don't have to subject yourself to that tedium if you don't want.
                                                                            • calvinmorrison 1 year ago
                                                                              Oh agree as a daily php writer. The core libs are all over the place for arguments. Doing something that's so elegant in perl results in a mishmash of weird array rules, too helpful built-ins that act weird like isset
                                                                              • asddubs 1 year ago
                                                                                It's one way for string functions and the other way for array functions. I have a little post-it on my monitor for it.
                                                                              • s1k3s 1 year ago
                                                                                > This is a subjective post about things that annoy me, some of the points are invalid and for sure people with far more context and brain power than I have have considered them. It is also to be expected that I take for granted things that would annoy other people.

                                                                                Great disclaimer, since most of the points raised in this article seem very nitpicky to me. This is understandable considering that OP's PHP work is about creating a language server and some benchmarking tool, both of which are definitely not the main use-case for this language. I bet your average PHP dev has no idea about the things mentioned in this article, nor are they interested in improving them.

                                                                                • alfredbez 1 year ago
                                                                                  I work on the same team as the author. I appreciate PHP in general, particularly because it contributes significantly to covering expenses (earning a six-figure income in Europe). While there is undoubtedly room for improvement in the language, this post highlights some valid points that we encounter in our day-to-day work on the 'large E-Commerce project' briefly mentioned at the beginning.

                                                                                  I hope that discussions like these raise awareness within the PHP community and eventually lead to solutions. Considering the impressive initiatives the PHP foundation has recently undertaken, I am confident that the language is evolving in the right direction.

                                                                                  Certainly, there are still individuals in the PHP world who may not grasp the essence of this post. In some tech interviews, I've encountered people stating that they 'don't know PHP, only Laravel.' I don't oppose Laravel (or WordPress or any other framework); I just want to emphasize that some individuals may not appreciate the underlying technology. Reflecting on my early days of programming, there was a tendency to exclusively focus on learning jQuery, neglecting the importance of understanding JavaScript.

                                                                                • 1 year ago
                                                                                  • atum47 1 year ago
                                                                                    I just launched an app that I've been using with my friends to collect and share memes. PHP on the backend and vanilla JS on the front end. Made a PWA out of the thing with some manifest and now I have something that I'm really proud of, that was put together in one week. If I see a funny meme I can just share it with my PWA and it will post it for me.
                                                                                    • nikeee 1 year ago
                                                                                      I'd love PHP to have proper primitives for working with binary data / buffers. You still have to use strings for that. Those strings are immutable, so performance will suffer. In JS, there are pretty decent APIs for that. Just copy them, they work good. There is an extension, but you have to build it from source and doesn't cover all of it.

                                                                                      Same goes for container data types. All you've got is array. No sets, no hashmaps, ordered sets, sorted sets. Array is just all of this at the same time. There's also an extension for that, but its API is... not optimal. I wonder how much faster some programs could be if the array wasn't used as the universal data type.

                                                                                      If one could use composer to install PHP extensions, that would be awesome. I fiddled around with WASM as a language for universal PHP extensions that can be loaded via composer, but there does not seem to be a lot yet.

                                                                                      • syspec 1 year ago
                                                                                        The beauty of PHP is that you're always seeing $$$ signs
                                                                                        • chuckadams 1 year ago
                                                                                          For "functions that return false", use thecodingmachine/safe which wraps those nasty builtins with ones that throw exceptions. PHP's gotten a lot better lately, but it's always going to need library fixes like that for its awful legacy builtins.
                                                                                          • alfredbez 1 year ago
                                                                                            I like this library and promote that wherever I can, but the safe library was even mentioned in the post:

                                                                                            > I love the smell of false in the morning, but despite that I do wish that all PHP’s built-in functions threw exceptions. We have the famous safe library which does just that! But if you’re like me then you don’t like coupling huge amounts of code in perpetuity to an external library.

                                                                                            • user3939382 1 year ago
                                                                                              I just wrap the ones I actually need that for and put them in traits (sometimes multiple related per trait). So it's internal, small footprint, and really needs 0 maintenance. This is also good for e.g. json_* when you want to provide app-wide defaults.
                                                                                              • chuckadams 1 year ago
                                                                                                Ah, I'd completely missed that. As for depending on an external library ... get used to it. Writing PHP without any external deps is strictly for one-off scripts -- and rarely even then.
                                                                                            • timw4mail 1 year ago
                                                                                              The first point is kind of silly: You can make rust-style constructor functions if you want, and have a private constructor to enforce the behavior.

                                                                                              Although it does require some boilerplate, which may seem like pointless extra work.

                                                                                              • alfredbez 1 year ago
                                                                                                I think this was not the point, see:

                                                                                                > [...] only to realise there the class has a private constructor or that there are static constructors which I should be using [...]

                                                                                              • reactordev 1 year ago
                                                                                                “Langauges such as Rust and Go do not have this problem, mainly because they don’t have the new keyword!”

                                                                                                Oh but they do. You should spend some time with those languages so you can do a proper comparison.

                                                                                                Go has had new for a while now.

                                                                                                • steveklabnik 1 year ago
                                                                                                  Go may (also in my understanding, it's not actually a keyword, but close enough?), but Rust does not.
                                                                                                  • reactordev 1 year ago
                                                                                                    Oh, excuse me, Box::new :D. At least in rust it’s an explicit method call instead of implicit.
                                                                                                    • agumonkey 1 year ago
                                                                                                      but it's a convention right ? there's nothing special about `new` IIRC
                                                                                                  • 1 year ago
                                                                                                  • user3939382 1 year ago
                                                                                                    I respond to every point below.

                                                                                                    In sum, the native functions should take iterators anywhere it can take arrays.

                                                                                                    Every other valid criticism he makes and many more I can wrap in the simple statement that: psalm needs to become the runtime type system which is hopefully and appears to be the (maybe distant) future.

                                                                                                    In the meantime you have 40% and quickly growing of those features in your IDE and 100% in your CI so it’s not a huge deal.

                                                                                                    Main takeaway for people who haven’t looked at PHP in 10-15 years or since the fractal article and would take the length of this post, which they don’t understand, to say “yep dumb php again” no.

                                                                                                    —————

                                                                                                    Constructors Only had this confusion once with my UUID library and it took me 3 seconds to remember the formula.

                                                                                                    "In attribute land this becomes:" I've never seen any code or library that uses attributes like this nor do I understand why you would. The only purpose would be static analysis, let's say with psalm, and that's just not how you use attributes in psalm. He says generics are tricky: in psalm they're trivial. The real problem is the best IDEs are still working on getting the integration right.

                                                                                                    Nested attributes strikes me as an extreme edge case that would only come up in some meta-level tooling you're making for the language which is the provided example. However in this special case presumably this can be accomplished through an extension, xdebug for example does this.

                                                                                                    Serialization he says is a problem then says, it's a solved problem (there are many such accepted ways to solve this) but then says it still annoys him so not sure?

                                                                                                    "No Variadic Promoted Properties" I'd like to hear the use case for. I've done very complex things in PHP and never needed this construction. A property can't have a static single type but then also consist of a collection of random types, in this case it would just be an array. It looks like another feature that is solved by psalm.

                                                                                                    Iterator to Array: Preserve Keys he says he doesn't know if it's wrong.

                                                                                                    Iterators vs. Arrays this is easily fixed by using the popular Functional library versions of these functions which I agree should be the default.

                                                                                                    Short closures cannot have statements" I have to convert between them so I kind of get it but would say this is an intentional choice. You can substitute a method call if you really want this.

                                                                                                    "Statement Blocks in General" That would be nice when and if it's very simple though having them anywhere could turn the language into kind of a mess to read considering what those blocks could contain.

                                                                                                    Functions that return false - basically everyone agrees on this, it's a conversion that's iterated on with each release and will just take time. The specific example he provides I have wrapped with an exception thrower for just this reason and never use the default.

                                                                                                    Inline Classes - he says he doesn't know if it's a good idea. I'd say no, having a reliable file system convention between codebases is a plus not a minus.

                                                                                                    • zelon88 1 year ago
                                                                                                      I realize it's an opinion blog, but can't help but notice that the author insists on comparing local compiled languages with PHP, a primarily server side interpreted language. Your static compiled binary program will continue working after a system upgrade, but your mish-mash PHP is going to break probably once per year.

                                                                                                      That said, I'll comment on the code style this author wants to use. It's flashy, confusing, and unnecessary. This person wants to show proficiency with the language by using all its features. That's not how you write good, readable code. Come up with some personal standards for yourself and stick to them. Stop mixing every possible style. You're increasing cognitive load.

                                                                                                      Continuing on, you want to use all the latest features of the language. That's great, but why are you trying to skin the cat three different ways in the same program? Pick one way and forget the others. If you can't fit all your code into short closures the rest will look like shit and confuse everyone else. I see this all the time with JS guys mixing bracket and dot notation. I feel like there is probably medication that can help with that.

                                                                                                      Then we get to the fact that you want everything to throw exceptions. Like file_get_contents. No. Just no. You're not supposed to rely on that function to tell you if the file is there. That's what file_exists does. If you've made it to file_get_contents and you don't know if the file is even there, you're doing PHP wrong. You can use that function with a URL and eval to execute remote code. You're not supposed to swing it around like a broken bottle.

                                                                                                      • darig 1 year ago
                                                                                                        [dead]
                                                                                                        • frank_bb 1 year ago
                                                                                                          [dead]