
What exactly do you dislike about PHP? and Why is your web language of choice better? - ACSparks

======
SwellJoe
PHP is pragmatic and pretty fast, but everything, everything, everything,
beyond the "HTML template language" bits, are bolted on with whatever tools
were handy at the moment. I'd be stunned if more than a couple hours of design
work went into the object system, the type system (where == and === are used
for evil rather than good), or even the standard library function names.

It has some strengths: Big library (not as big or as high quality as CPAN, so
if library support is what you need, go for Perl), a lot of example code (but
it's mostly horrible quality...even good examples are pretty bad in spots),
and really easy deployment. So, if you're building an Open Source project that
you want a lot of people to use, it's a great choice--PHP is available on
every hosting server on the planet. Or, if you need a "blank-plus-this-widget"
you can probably find the "blank" already written in PHP and then build your
"widget" on top.

But, if you're starting from scratch, why commit yourself to working with a
shoddy language for the months or years it'll take to finish? There are good
imperative languages out there for web app development: Ruby and Python, in
particular. Though the frameworks craze for these languages are partly to
bridge the gap that they have with PHP (they're all missing a "view" layer for
the web, because PHP is a reasonably powerful, if ugly, template system), and
a lot of the other crap just makes things ugly...they get built for one
particular application and then stretched for general-purpose use, and in the
stretching they get a bit misshapen and hard to fit into any specific task.

Anyway, Ruby and Python are pretty and reasonably consistent languages that
are nice to work with. PHP is neither. Perl...well, it ain't necessarily
pretty, but CPAN is hard to beat when you just want to get the job done...and
you can treat it as a functional language pretty effectively, which is all the
rage around these parts (and you'll probably want to after you see the bolted
on object system).

------
gyro_robo
This is fairly well-trod territory:

<http://www.google.com/search?q=why+php+sucks>

A good resource for comparing languages is the shootout:

[http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=all⟨=all](http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=all&lang=all)

Most people just refer to the overall scores, but what's more interesting is
seeing the same program done in different languages.

This one is pretty straightforward:

[http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=nbody⟨=php&id;=0](http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=nbody&lang=php&id=0)

Compare to the same thing in Python, Ruby, Scheme, Common Lisp, and Haskell:

[http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=nbody⟨=python&id;=0](http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=nbody&lang=python&id=0)

[http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=nbody⟨=ruby](http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=nbody&lang=ruby)

[http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=nbody⟨=chicken&id;=3](http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=nbody&lang=chicken&id=3)

[http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=nbody⟨=sbcl](http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=nbody&lang=sbcl)

[http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=nbody⟨=ghc](http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=nbody&lang=ghc)

------
ramen
I often find myself defending PHP. It seems to be very unpopular lately, at
least by some very vocal individuals on the web. I like PHP, and here's why:

It runs everywhere, has lots of libraries, and most of my friends know it.

That, for me, is huge. It's enough for me to forgive, tolerate, and even enjoy
programming in the language.

Anyway, here's what I don't like:

The lack of a decent module system.

The lack of closures.

The weird reference semantics of objects in PHP4. PHP5 is way better in this
regard, but now I have to worry about whether my code will still run on PHP4,
and whether or not I will need it to.

The clumsy templating syntax. Short tags help, but I'm supposed to feel guilty
if I use them.

The need to use unreliable third-party software to get bytecode
precompilation, causing me to worry about the performance costs of modularity.
(!)

Magic quotes. And the fact that I may need to undo them depending on the whims
of system administrators.

Arrays. I wish dictionaries and lists were separate concepts like they are in
Python and many other languages I want to interoperate with.

The name. I hate when I have to explain what PHP stands for. I feel like
enough of a geek as it is.

------
jward
PHP is ugly.

Really, I could go on a rant about speed and security, but it's just ugly. I
do most of my coding in Python now days which spoils me. I look at php and
it's a nasty mashup of code, data, and structure all rubbed into one nasty
little steaming pile. Python is pretty and that's why I like it. It's easy to
read, easy to understand, and does not explode into a visual cacophony like
I've seen most php projects do.

I'd use php for a small simple one off thing because it is stupidly simple to
get a page working with no fuss. I also have no issue using php products like
Wordpress or PHPBB. My first web startup I wrote in php and it was a pain to
maintain after a while. Anything large I'll stay away.

Just because it's ugly and I have to stare at it.

~~~
ACSparks
Have you checked out Code Igniter? It is a php framework that implements the
MVC design pattern. Forcing the seperation of the different layers makes
things much "prettier" in my opinion.

<http://www.codeigniter.com/>

------
aantix
Have you seen the function list? <http://www.php.net/quickref.php>

It's a nightmare. How about some organization? How about a hierarchy? How
about some terseness?

~~~
ramen
If you think that's bad, you should try C sometime.

~~~
whacked_new
Yeah, I don't really understand this. My first language was C, and all these
C-like languages look quite similar in syntax. I never thought these were
"pretty," but they don't really stroke an emotional component in me.

~~~
ramen
My point is that PHP's lack of namespace hierarchy is just like C. In fact,
most of PHP's libraries are very close to the underlying C libraries. The lack
of apparent organization is mainly due to the fact that PHP pulls all these
different, independently-written libraries together. If you were writing C, it
would look about the same, except that you'd have to go out and find all these
libraries and put them together yourself.

------
mdakin
"You can nest function declarations, but with limited effect. Nested
declarations do not limit the visibility of the inner-defined function, which
may be called from anywhere in your program. The inner function does not
automatically get the outer function's arguments. And, finally, the inner
function cannot be called until the outer function has been called."

That's from "Programming PHP" by Rasmus Lerdorf et al.

This sort of messiness, repeated dozens of times in various ways is why I try
my best to avoid PHP.

------
walesmd
I actually see the PHP bashing as dieing down quite a bit, Now that the Ruby
on Rails craze is over with (the language is awesome, but I'm glad to see some
of the hype go away).

I think people are finally understanding that there is room for both languages
(and more) and each language has it's strengths and weaknesses than can only
be leveraged (or overcome) by someone truly comfortable with that language.

~~~
dshah
Are you sure the Ruby on Rails craze is over?

I didn't get that memo.

------
ACSparks
There seems to be much talk thrashing the web language incumbent PHP. What
exactly bums you out? and why is your language better?

~~~
papersmith
The best way to find out is to quickly go over a "clean" language and see for
yourself. Ideally Lisp, but ruby or python will do if you're impatient.

------
jaggederest
Well, mostly just that PHP has been extended far beyond the simple templating
language it was designed as.

My language of choice (ruby or haskell, take your pick) was designed for more
general tasks, and so is simpler to write the more general web apps people are
building now. I would still like to use PHP as my template language, though.

PHP is still very fast when it comes to templating, but it's not very fast at
all when doing any sort of number crunching. Ruby suffers here, too, which is
why I'm trying to use haskell for my current project.

------
brlewis
Look through Chapter 4 of the BRL manual for paragraphs marked "Advocacy".

<http://brl.codesimply.net/>

------
kogir
Every time I have to type a '$' in front of a variable name I have BASIC
flashbacks from my prepubescent years.

That did me in. Really.

------
Tichy
It has an escape_mysql_sql method - that alone says everything for me. It's
just a big, messy mess.

