5 ms·
PHP as a language really is that bad. It's probably the worst popular language right now as far as how difficult it is to write correct code. Especially because
by ragnese 6y ago
PHP as a language really is that bad. It's probably the worst popular language right now as far as how difficult it is to write correct code. Especially because a lot of times your code will seem to run fine until it doesn't. It's also got a tacked on type system that is not robust or expressive at all, so your typing is worse than pre-generics Java. Only JavaScript rivals it. It has no async/multi-threading either, so probably JavaScript is less-bad.
I don't know that I'd call it insecure, necessarily. I'd call C an insecure language. I'm not an expert on all the various standard library functions that you aren't supposed to use anymore. Just make sure if you do SQL that you go through some interface that prepares your statements for you and never just shove user input into a SQL string you build yourself.
On the other hand, as people have already mentioned, there are some genuinely best-in-class libraries and frameworks written in/for PHP. Laravel and Symfony are extremely productive, pretty easy, full-featured, and polished.
It's my opinion that people who defend PHP as a language mostly fall into two camps:
1. They've never (significantly) used languages that are much better. Maybe they've only done PHP, JavaScript, Java, and C; and think that all languages are pretty bad.
2. They are conflating the language with the ecosystem. When you choose Laravel for a project, you're choosing a solid framework in spite of PHP-the-language. You're probably not really choosing PHP per se.
- mns 6y ago"It has no async/multi-threading either, so probably JavaScript is less-bad." Screwdrivers are really that bad, you can't even use them to pound a nail properly...
- ragnese 6y agoWhat? PHP is a language primarily for backend web server code. Having async is huge for performance on the backend, which is mostly IO bound, rather than CPU bound. So, I think you have it backwards. Async is unnecessary in many places, but backend is the place where it's very important.
- mns 6y agoPHP started as a scripting language and had/has many other issues and fundamentals that had/has to get right first. Don't blame PHP or Javascript for things they were not initially built and meant for, when there are other languages out there that can do what you need and have a more solid and tested foundation.
- ragnese 6y agoSo what is PHP for, then? Everyone seems to be using it for backend web projects. In my opinion, it has no valid use case that isn't done better by something else. The only thing I can think of is for shell scripting when your bash script is a little too long. It's also been around for, what, 30 years, and still hasn't changed its broken fundamentals. And it isn't going to. It needs to be deprecated. It's run its course.
- mekster 6y agoAnd your recommendations are?
- ragnese 6y agoFor backend? Kotlin. Hands down. All the benefits of the mature Java ecosystem, but with a language that is vastly superior to Java, itself. You get coroutines, threads, strong static typing, etc. Not the perfect type system, because it's still limited by the JVM, but much much better than Java, PHP, etc.
- zowanet 6y agoJavaScript's async features are made possible because of its event loop (Node.js is essentially V8 + libuv). You can use one of many event loop implementations with PHP, including libuv, if you so wish.
- ragnese 6y agoSure. But JavaScript has Promise built in to the language these days. With PHP you'd have to use a third party extension, like swoole, if you want something like that. Or write your own, of course. But should we need to do this for a 25 year old backend language?
- fimbulvetr 6y agoThis is just FUD. You didn't give us any real use cases to agree with or refute, only your opinions. Lots of people and companies do very productive, very real, very "typed" and very effective applications and code in PHP. I am stunned that you are writing "because a lot of times your code will seem to run fine until it doesn't" as it wouldn't be such a widely used programming language if that was the case. Your entire comments reeks of trolling.
- spaced-out 6y agoDo hashes in PHP still break if one of their keys starts with a number?
- zowanet 6y agoThis[1] works fine in every version of PHP since at least v4.3.0 (released in 2002). Do you have a concrete example of this supposed breakage? [1]: https://3v4l.org/DWDLn https://3v4l.org/DWDLn
- ragnese 6y agoI think the parent was referring to this: http://phpsadness.com/sad/47 http://phpsadness.com/sad/47
- spaced-out 6y agoIt seems so, my memory must be from using an older version.
- ragnese 6y agoWell, I thought it was a given that this is my opinion. But let me go ahead and address your points: > You didn't give us any real use cases to agree with or refute, only your opinions. There are tons of sources online for all of the inadequacies of PHP as a language. The "fractal of bad design" essay is the quintessential one and even though it was written about a decade ago, many of the things are still true. Things such as `==` literally being incorrect, logically. In one of my previous "anti-PHP" comments, I made a point that even a couple of seasoned PHP developers were surprised about where if you use the built-in `array` type as a dictionary and you try to use strings as keys, it will convert those strings to ints if they look like numbers. If you don't know your keys ahead of time (such as storing an association of file names in a directory to their size), you can have surprises when you try to use the array_* functions assuming that your keys are all strings. This behavior is totally insane, even for a dynamically typed language. Or how about the fact that when you use `foreach`, it leaves an allocated reference to the last element in the collection you're iterating over? But, it's PHP- who cares about memory bugs? I could go on forever. But- let me guess- "You can write bad code in any language", right? Or "all languages have warts"? PHP has more warts than anything else I've ever used. Period. It has so many warts that it has probably caused a ton of economic harm that could've been prevented. > Lots of people and companies do very productive, very real, very "typed" and very effective applications and code in PHP. You can write code in Brainfuck if you want. You can even write correct code if you work hard enough. Like I said, PHP has some really strong libraries and frameworks. The language is garbage. If these companies didn't need a particular PHP library and just wrote it in PHP, anyway, I truly believe they would've had an even better, even cooler, even more profitable project if they'd chosen almost anything else. > I am stunned that you are writing "because a lot of times your code will seem to run fine until it doesn't" as it wouldn't be such a widely used programming language if that was the case. See my examples above. Everything looks great, and your tests even pass. Then all of a sudden somebody has a username of "123" and your site breaks. It happens. I honestly can't explain why it's such a widely used programming language, other than pure inertia and people not wanting to learn anything else. JavaScript at least has the excuse that it's really the only option in the frontend. > Your entire comments reeks of trolling. Depends on your definition of trolling. At this point, I do get pleasure from pointing out PHP's flaws. But I never say anything that I believe to be untrue. And underneath any snarkiness, I genuinely want people to write better, more performant, and more correct software, and to have an easier time doing it. Many people haven't moved outside of "enterprise" programming languages, so they don't even realize how bad stuff like PHP is at converting business logic into code. Try doing a real project in Kotlin if you like static types. Try Clojure or Elixir if you like dynamic types. If I come across as troll-y, it's because I'm kind of exasperated that people still think PHP isn't a bad language, and I can't decide if they're just trolling...
- mekster 6y ago> 1. They've never (significantly) used languages that are much better. Maybe they've only done PHP, JavaScript, Java, and C; and think that all languages are pretty bad. And you don't even mention the languages that you think are better at certain points? I've mainly used perl, PHP and JavaScript (TypeScript) but I never blame the languages but just struggle to get the thing done while I'd imagine those people who keep complaining about languages (Is it so hard to learn a few best practices for a language?) barely get things done.
- ragnese 6y agoI didn't want to be accused of shilling or something. I really like Rust, Kotlin, and Swift right now. But I'd never try to use Swift outside of writing iOS or macOS apps, right now. I'm very excited about Scala 3 as well. I've never used Haskell on a real project, but I'd love to try it out "for real". I found Clojure and Elixir to both be well designed and ergonomic languages as well, but I'm really not a fan of dynamic typing. I didn't dislike TypeScript when I used it a couple of years ago, either. Mostly I just found the whole frontend ecosystem very overwhelming, but that wasn't the language's fault. Also, whatever to your passive aggressive remark that's supposed to imply that I don't get work done. That wasn't very nice.