I get hating on PHP is a meme, and the language certainly has faults, but I feel like itâs no more arbitrary than how JavaScript behaves. And just like JavaScript, if you follow modern standards and use a modern version, itâs a much better experience. The language is only as good as the programmer.
I didnât mean it as a flex. It was a commentary on how the most commonly used programming language in current days is just as flawed as the most commonly used programming language in the past (in web development). Bad programmers are going to write bad code, regardless of the language.
How about "php enables me to code like a moron", or even better, "php breaks common conventions and forces me to think about every little detail and special edge case, slowing me down if I don't want to accidentally 'code like a moron' "
Nested ternary operators emerge because of the lack of if/switch expressions (which is C fault), so they are "useful" (they shouldn't be). However, PHP is the only language that treats it as left associative. This has 2 problems:
You are forced to use parenthesis. Some (insane) people might do:
(cond1) ? "A" :
(cond2) ? "B"
: "C"
And it makes sense. Its ugly af, but it makes sense. But PHP now forces you to use more parethesis. It's making you work more.
It breaks convention. If you come from any other language and use ternary operators, you will get unexpected results. After hours of banging your head against the wall, you realize the problem. And now you have to learn a new edge case in the language, and what to do to actually use the language.
"But you shouldn't use ternary operators anyway! Use if/switch/polymorphic dispatch/goto/anything else"
True, but still, the feature is there, and its bad. The fact that there are other alternatives doesn't make the PHP ternary operator worse than other languages' ternary operator.
PHP works against you. That's the problem. The ternary operator is not a good example, since there are alternatives. But look at something so simple, so mundane like strpos.
If strpos doesn't find returns false. Every other language returns -1. And if you then use this value elsewhere, PHP will cast it to 0 for you. Boom, your program is broken, and you have to stare at the screen for hours, looking for the error.
"BuT yOU sHoUlD AlwAyS cHEcK tHe rETurN eRRor!"
And even if that's true, if we all must check the return value, does PHP force you to do so? Like checked exceptions in Java? Or all the Option & Result in Rust? throws, throws, throws... unwrap, unwrap, unwrap... (Many) people hate those features
But if you code like a moron the code should still behave as expected. People who code like this deserve a special place in hell, next to languages that behave like that.
I say that php breaks math entirely, and is therefore bad.
"" == null returns true
null == [] returns true
"" == [] returns false.
In more recent versions it gets worse, because it has
0 == "any text" return true,
"any text" == true return true,
and 1 == true return true
So indirectly 1 = 0, and now math is more directly broken.
Ever wondered about the array_fill function? It can be baffling. Try filling an array with a negative index:
array_fill(-5, 4, 'test');
Many languages would throw an error, but PHP? Itâs perfectly fine with this and you get an array starting at index -5. Itâs like PHP is the Wild West of array indexing!
Absolutely, many languages do allow negative indices. The intriguing part about PHP, though, is that its âarraysâ are actually ordered maps (or hash tables) under the hood. This structure allows for a broader range of keys, like our negative integers or even strings. Itâs a unique design choice that sets PHP apart and allows for some really interesting usage patterns. Not your everyday array, right?
Hating on php is one of the reasons i left reddit. This is just people who donât use php hating php for some reason. You can do dumb examples like this for any language. Low effort and funny for children.
Your feelings are valid. I wonder though, would you put up this level of defense for posts making fun of arbitrary parts of non PHP languages?
You are not your favorite language. And I find most criticisms of most languages to be very valid. I don't think the intent of OP is to insult all PHP programmers. It's okay to like a language that has problems. All languages do.
I'd wager prevalence is part of their problem. Jokes get tired after a while, but that doesn't always mean they stop.
PHP, like any language, has its problems, but it seems to get poked at a lot more often. But making the same joke over and over has been a problem long before reddit was a thing.
I took this more as a light-hearted poke at a silly edge case. As someone who used to build static analysis software for various languages, including PHP. This gets a chuckle out of me as it takes me back to having to deal with these exact types of edge cases.
The title of this post is calling php a âmemeâ did you read that part? Then it just uses some stupid ternary example no one does and that other languages exhibit so what is the point other than purely hating on php?
Is $a equal to 1? If so, we're "set" to the value on the left, which is "one", if not then we're set to the value on the right, which is $a == 2. $a is not equal to 1, so we're set to the right value, $a == 2.
This replaces the relevant part, $a == 1 ? "one" : $a == 2, with $a == 2. So we're left with:
$a == 2 ? "two" : $a == 3 ? "three" : "other"
Next, is $a equal to 2? If so, we're set to "two", if not we're set to $a == 3. The comparison is true, so we're set to the value on the left, "two". The relevant part here is $a == 2 ? "two" : $a == 3 only, so it replaces it with "two" cause again, PHP is only associating with its immediate pair. So now we're left with:
"two" ? "three" : "other"
Finally, is "two" truthy? If so, we're set to "three", if not we're set to "other". Since "two" is truthy we're then left with "three".
If you think PHP is weird, go look up ZZT-OOP, the scripting language from Tim Sweeney's first game.
(No, a scripting language for game characters doesn't need integers. If you need to count, you can do that by moving blocks around on the game board. It's halfway between LOGO and Minecraft.)
"I don't know how to stop it, there was never any intent to write a programming language [...] I have absolutely no idea how to write a programming language, I just kept adding the next logical step on the way."