5 ms·
I think we need to stop with all this PHP hate. Sure, 10-20 years ago the language was more hacky than anything, but nowadays its a solid choice for backend st
by tacker2000 3y ago
I think we need to stop with all this PHP hate.
Sure, 10-20 years ago the language was more hacky than anything, but nowadays its a solid choice for backend stuff, with lots of activity, new innovations, good, proven frameworks (Symfony, Laravel) and also lots of people who have experience in it.
I have a few projects running a PHP API with a JS frontend (Vue in my case) and it works pretty nicely. Best of both worlds!
- deprecative 3y agoPeople love to hate on PHP then love to love JavaScript. It's bonkers. PHP is clearly better than JavaScript, it's just that we're all forced to use JS.
- scq 3y agoI really do not understand this take and have to assume people who say this have not deeply used PHP. It has a large variety of bizzare language features that make JavaScript look downright well-designed. Examples off the top of my head: * Lists and dictionaries being the same data type ("array"). This makes it impossible to distinguish between an empty list and an empty dictionary, good luck encoding that JSON. * Arrays are pass-by-value * '123' == '+123' evaluates to true * '0' == '0.000' evaluates to true * `$a = true; $b = false; $c = $a and $b;`, $c evaluates to `true` * Closures requiring you to explicitly list every variable from the parent scope you want to use * References (&$var) have a lot of footguns * array_key_exists and property_exists taking opposite parameter orders * stdlib naming in general being pretty bad, with the stated justification being that strlen() was used as a hash function in early PHP versions, so functions were named to achieve an even distribution: http://news.php.net/php.internals/70691 http://news.php.net/php.internals/70691
- rafark 3y agoAre you serious? https://gist.github.com/shapkarin/b3fbeaca95ef69df177b https://gist.github.com/shapkarin/b3fbeaca95ef69df177b
- blueflow 3y ago* no way to get the errno from fopen (relevant for concurrency things)
- ptx 3y agoHere are two more: * The null-coalescing operator is also an are these even valid identifiers-coalescing operator – here $result is 2: $myvariable['x'] = 1; $result = $myvvvvariiiiableee['x'] ?? 2; * '0e123' == '0e456'
- sph 3y agoGP didn't say PHP is a good language. GP is saying that many hate PHP while praising JS, which is another impressive pile of crap on many fronts: semantics, standard library, ecosystem. All those bad things about PHP you've listed go well with Gary Bernhardt's WTF video about JS's inconsistency. JavaScript is not well-designed however you squint at it, and claims that it's gotten better must come from people that have not used any other language before.
- scq 3y agoI'm familiar with the Wat talk, the flaws in JS are not nearly as egregious. I'm not saying that JS is well-designed, just that PHP is so badly designed that it makes JS look good by comparison.
- CivBase 3y agoI hate both. But to be fair I started hating JS 15 years ago when IE6 support was still important, and I haven't touched PHP in 10 years so it may have improved significantly. I'll still use either if I run into a proper use case for them.
- candl 3y agoFor scripts I use Python, but I like to use PHP for short quick scripts when a database is involved since all it takes is to install php and php-pdo to have a consistent api for db access to get started with, which for python is not the case. But from time to time I am reminded how bad PHP and outright dangerous can be. Just the other day I had an array like this: ["123"=>"foo", "321" => "bar"] on which I used array_keys expecting to get ["123", "321"] as a result. Surprised why my script was not working the way it was supposed to I found out that the result was actually [123, 321] instead. Yep, PHP casts strings to numbers in this case when it can. I will hit a "gem" like this every now and then, there are plenty of such dumb things scattered in PHP that will bite you the least expected way that makes me stop and think to use something else.
- drcongo 3y ago> all it takes is to install php and php-pdo to have a consistent api for db access to get started with, which for python is not the case What's the difference between that and `pip install psycopg2` (which actually seems easier to me)?
- candl 3y agopdo is a common interface layer for databases for php, like jdbc in java or ado.net in C# so I can use the same api for any supported database. In python technically dbapi standard exists for the same task, but the driver apis annoyingly vary so much between themselves that if i have to i go with sqlalchemy, but it's no longer a lightweight solution
- drcongo 3y agoThat makes sense, thanks. It seems I somehow forgot that databases other than Postgres exist.
- mikl 3y ago> nowadays its a solid choice for backend stuff Hell no. PHP is awful for background processing. I do DevOps for a bunch of different languages (Node.js, Elixir, PHP, Java) and PHP is always the problem child. Poor concurrency, memory leaks, general RAM bloat, etc.
- gumballindie 3y agoMemory leaks in PHP? Poor concurrency? Thats new. However what you describe is more of a developer skill problem. Although i’d use other languages for background processing - ie python or nodejs PHP can be pretty solid too but you know, use the right tool for the task at hand. Being religious about a language is a symptom of poor engineering skills - common in the php world, where they tend to use it for everything.
- mikl 3y ago“developer skill problem”. Nice insult there, I’m tempted to respond in kind, but I’ll just point out that PHP doesn’t have much support for async operations of any kind, and all the big frameworks are written in single-threaded “blocking” fashion, so the only way to have parallel processing is to run multiple instances of the program in parallel. And if you google for “php memory leak”, you’ll get a lot more than 0 results.
- gumballindie 3y agoSorry for making it sound as an insult, i should have phrased it differently. Since php scripts are meant to be run once per request memory leaks are not an issue - any build up gets “reset” once execution ends. There are however shit frameworks that have circular references to objects and do all kinds of crap that builds memory up - easily avoided by parallel queue consumers. Threading and async are non issues given my statement above, hence me blaming on the dev’s skill and not understanding what the language does. For instance, you dont normally start a background process with an event loop to handle stuff. You start queue consumers at set intervals that run in parallel, or scripts that process batches of code - thus mimicking parallelism in a classic multi threaded app. This way you reduce the blast radius, are guaranteed that at least some data will always be processed and avoid memory leaks alltogether. No need for “conscious” async since its async by nature. However there is nuance in everything. Would you be able to provide a specific example of where you end up with such issues so i can better detail an example of how i would approach it?
- knorker 3y ago10-20 years ago it was a terrible language for the time. Nowadays it's a fine language for the year 2000.
- usrusr 3y agoIt's a terrible language full of dangerous quirks that require every single line to be carefully crafted with great knowledge or else the "works most of the times but isn't quite what you want here" footguns will get you. And many of those quirks exist right at the surface, no framework can remove those. Sure, it's possible to succeed using php despite all this, but that does not make it a non-terrible language.