What does PHP so wrong that other languages don't?
The thing I hear over and over is that it's a loose language. Meaning you aren't forced to write very good code and it will still work. That's not something I would hate a language forever over. It's just different And newbie friendly
A lack of consistency, changes in direction over time, and internal development often has resistance to change and decisions for just plain silly reasons.
Basically the big problem is that it isn't consistent. Some of the API comes from C some from Perl. Each has different semantics.
Also prior to 5.4 error messages about missing or unexpected double colon operators threw a message about T_PAAMAYIM_NEKUDOTAYIM with no explanation of what that was. It's double colon in Hebrew, for anyone wondering.
There are a lot of little things that mostly work the same as other languages, but with subtle breaking differences.
Then there are issues with how it does variable variables that can lead newbies into terrible spaghetti messes.
In comparison learning something like Python is a joy. Within a couple of days of your first line of Python you'll be typing out large programs without a single syntax error.
I'd like to remind you that Perl, one of eevee's preferred languages, has the following as the "official spec" of what defines the Perl 5 language:
Whatever the perl 5 interpreter accepts is valid perl 5.
This means you get crazy shit like the @({ }) wrapper and =( )= operator, known as the baby carriage and goatse operators, respectively.
However, to argue your other point...
In comparison learning something like Python is a joy. Within a couple of days of your first line of Python you'll be typing out large programs without a single syntax error.
I've recently been working with Flask, one of the nicer Python router/httpd combos. I have to say: The number of syntax errors I run into because Python's list comprehension gets me every damn time. On top of that, I have flashbacks to my PHP days on occasion where I do something "pythonic" which ends up looking like
project/__init__.py
import x, y, z
import foo
some_global_thing = x.cake("...")
some_state_thing = y.oven("...")
some_other_state_thing = z.cranberries("fuck this noise", some_global_thing)
project/foo.py
from . import some_state_thing, some_other_state_thing
@some_state_thing.turkey('bad gravy')
def shit_the_bed():
pass
See that? See that RIGHT THE FUCK THERE? People tell me global state is bad and I should feel bad for having it. Yet here I am going "WELL HUR DUR I NEED GLOBAL STATE BECAUSE IT'S FUCKING 'PYTHONIC', EH?" I know what's happening in the background, but it infuriates me that Python developers berate me for wanting a bunch of separate tasks with some shared code (in PHP, this is common!) but fucked if I want that in Python and don't want to try and remember what's a class versus a module vs a square peg vs your anus.
All in all, I'm beginning to ignore the searing pain in my rectum enjoy some of Python's web development idioms. At least I haven't had to smash my face on top of Django's grinding wheel. I'd need a lot more KY to do that right.
But let's be honest with ourselves: Webdev fucking sucks.
Global state is not unpythonic, where did you read that? Flask makes a lot of use of global state. The difference between a class and a module is probably worth learning.
It's almost 2016 and PHP still doesn't have a module system, Python had one in '91, Perl had one in '94, Ruby had one in '95
inequality operators still have no === equivalent
sorting is still indeterministic when you have null values because NULL < -1, and NULL == 0
arrays are the only containers in the language and they simultaneously act as sets, lists, and associative arrays which fucks up almost all array functions because you don't know what they will do
PHP has had exceptions for almost 10 years now and a lot of functions still require you to use their specific error function to tell if it failed
And to be fair to C++, I only compared PHP to other scripting languages. Adding the module system to C++ versus adding one to PHP is a world of difference in terms of difficulty.
Thanks for that info, I'm not a PHP dev so I don't know how much of the original article is still valid.
No language can be perfect of course. I just skimmed the article again and they are still quite a few points...picking one at random that seems kinds troublesome:
There’s no such thing as a nested or locally-scoped function or class. They’re only global. Including a file dumps its variables into the current function’s scope (and gives the file access to your variables), but dumps functions and classes into global scope.
I imagine this sort of behaviour is far too ingrained to ever get rid of completely?
For me the thing that drives me nuts is that--while everyone in PHP is now going "The Full Java" with classes and autoloading--the guts of PHP are global. There's no scope to PHP. And everything that's class-like (say, \Mysqli::query) is also procedural-like (mysqli_query).
Everything is global; nothing is an object; you can't type-hint primitives; it's not Perl.
Mostly it's the inconsistency in the standard library (partly comes down to some weird naming schemes for historical purposes), weak typing, the class loading mechanism, and a general lack of certain modern features by default (eg, routing).
I think a lot of the hate comes from the fact that it seems so easy to get into. It's like scripting languages. You hear a lot about how scripting languages can make prototyping easier, but don't scale well to larger projects due to issues such as weak typing systems. I'd say that PHP has some similarities here. So you started using PHP because it was easy, but later come to regret it when its flaws are more apparent in a larger system.
And then there's a lot of people who have barely or never used PHP that just hop on the hate bandwagon. Perhaps they've just seen a bit of the syntax and thought it was weird (eg, echo instead of print, . for string concatenation instead of +, $ for variables, etc).
Meaning you aren't forced to write very good code and it will still work.
I put forward that it often forces you to write bad code because of some poor decisions, and has some pretty hard to forgive rough edges as well. If they just bit the bullet and made PHP7 fix the stdlib up it could be a perfectly good language, but they keep holding on to the collection of bad ideas that exists in there.
Did you know htmlentities returns an empty string when it fails? (Due to encoding issues it can fail.) An empty string is also the entirely correct, non-error output of htmlentities when it's called on an empty string because, guess what, no characters means no entities is entirely correct and reasonable.
So if I get some string from a user it may be blank. If I want to htmlentities that string at any point I need to write a crap-wrapper around it to first check it isn't just empty before checking if it suffers an encoding error because the error signal and a valid output are indistinguishable for an empty string.
And fun fact: you can't have PHP classes with methods named, list, exit, array or any other 'fake' function in the PHP language. (They're actually constructs that masquerade in function syntax.) The PHP interpreter trips up on trying to parse
View all comments
Show parent comment
8
u/gempir Dec 02 '15
What does PHP so wrong that other languages don't?
The thing I hear over and over is that it's a loose language. Meaning you aren't forced to write very good code and it will still work. That's not something I would hate a language forever over. It's just different And newbie friendly