

What do hackers think of PHP? - amrithk

Just interested to know, what do people in this forum think about PHP as a backend language for a website?
======
giltotherescue
I maintain a site that receives over half a million pageviews per day, not
including API requests of XML feeds. This site runs on 3 medium range
commodity web servers and 2 database servers, and there's plenty of capacity
left.

Don't let the scaling police and architecture astronauts fool you: with the
right architecture in place (i.e. a framework like Cake or Zend) and a smart
scaling strategy (opcode caching, object caching, page caching, etc), PHP is a
great choice for web applications.

Sure PHP has a low barrier to entry, which can lead to poor coding practices,
but that shouldn't be a reason for people to express an absolute hate for it.
Rather, it's important to stress continual education regardless of which
programming language you choose.

~~~
jrockway
Sure, it scales. But it isn't a very good language. (The word "blub" comes to
mind.)

Here are features I like to have (in no particular order):

    
    
      * lexically-scoped variables (and closures)
      * lambdas
      * continuations
      * macros
      * an object system with a MOP (PHP and Java fail miserably here)
      * powerful regex engine (can be added via libraries, so not too critical)
      * extensive module library
      * flexibility (I want to write code my way, not the way someone else thinks I should write it; bye bye, Python.)
    

Things that are nice to have:

    
    
      * multiple dispatch OO
      * partial evaluation
      * laziness
    

PHP has none of these features. That's why I don't use it and don't recommend
it. And oh yeah... PHP is a templating system too. I would rather get that as
a library, not a core feature. (But I won't count that against them.)

So what language does have all these features? None :)

But, Lisp and Perl are good compromises. CL does everything except
continuations and having a decent module library; Perl does everything except
have pretty syntax and macros. Sadly neither of those languages has (by
default) the "optional features", which is a shame. I ranted about this on my
blog:

<http://blog.jrock.us/articles/Syntax%20and%20features.pod>

Anyway, PHP is junk in terms of a programming language. It's fine if you don't
know how to program, don't know what abstraction is, and don't like using
libraries.

~~~
wvenable
Your list of features has nothing to do with getting things done. They are
almost completely academic.

~~~
SwellJoe
True of maybe half of those features...but the other half? Well, if you don't
know enough to miss them, I don't have any way to argue with you--there's no
common language in which we can converse about them.

But, I feel uncomfortable every time something I write takes two or three
times the lines of code because of what the language lacks. First class
functions or lambdas, closures, and a good library fall into this
category...and PHP fails on all of them (there are many PHP libraries, but
most are buggy and rather scary, and the standard library has ad hoc'ery
written all over it...I like for the standard library to at least be a little
bit planned out rather than crammed in via 3000 or so functions in the same
name space).

But PHP is a perfectly valid language for many classes of problem. Just be
careful not to use it for the classes of problems for which it is extremely
poorly suited.

~~~
calpaterson
>Well, if you don't know enough to miss them, I don't have any way to argue
with you--there's no common language in which we can converse about them.

While I agree with your actual premise ; this statement is pretty bad form. It
is the logical equivalent of a Christian saying that in order for me to
critique his faith, I must become a Christian.

Replying, "you wouldn't know; you're an imperative programmer" is moot; maybe
he is an imperative programmer - but he could also be correct. There is no
connection between the two. Deductive logic has never been allowed in the
scientific method, which is, ultimately, the barometer of truth.

I'm aware that Graham is the originator of this somewhat popular meme, but
it's a wrong popular meme. The nature of ignorance of certain desirable
features can only explain why people don't immediately demand them; it doesn't
prove their usefulness.

~~~
SwellJoe
"Replying, "you wouldn't know; you're an imperative programmer" is moot"

That's obviously not what I said. My reply was, "If you believe all of the
features listed above are useless in a real world development situation, I'm
not capable of convincing you otherwise, as we're going to be speaking very
different languages". I think there is a difference, though I can see how it
comes off as arrogant. It wasn't really intended that way--I'm not a great
programmer, and never claimed to be. But I know what makes me (as an
adventurous, but not necessarily brilliant, hacker) more productive is good
tools. And first class functions, closures, and a great set of libraries (like
that found in Perl, Python, and to a lesser degree Ruby), are the tools save
me lots of time. When I develop in PHP, and I do so pretty frequently, I miss
all of those features constantly and my code is longer, less readable, and
harder to maintain.

My point was if you haven't worked with a language that has those features you
wouldn't be aware of how much time, and how many lines of code, they can save
you. I'm not a smug lisp weenie pushing the blub paradigm (though there is
definitely something to the argument) or implying that imperative developers
are the scum of the earth. I'm a pragmatic sort of fellow...if it works, use
it. But if something works better, why not use it instead?

That said, one of the places where PHP is a perfectly valid language is web
applications. Some of the largest applications in the world run on PHP--
Facebook, many Yahoo sites, etc. But they also have lots of languages doing
the non-frontend work, because PHP is really horrible at a lot of backend
tasks. Data and systems management, for example, where Perl and Python, or
Java (depending on scale and performance requirements and existence of
libraries), would be a better choice.

~~~
calpaterson
Sorry, I didn't mean to characterise you wrongly, I only rephrased the actual
quote because it fitted better with the deconstruction. I actually do think
it's a reasonable representation of what you said (or, more pointedly, the
concept in general).

Good reply, looks like I made a mistake about part of your opinion, but I
can't agree with you about not being the value of these features being
difficult to explain. I always just explain situations where
closures/anonymous functions work well (while I'm not much of a web
programmer, I can think of a couple of examples). I agree, there is something
to the blub concept. There certainly is a spectrum of languages.

------
rickmb
PHP is without a doubt the worst structured language I've ever coded in.
Probably the crappiest language after VBscript.

But I use it for anything web-based because it gives me guaranteed results,
anytime, anywhere, on whatever scale on whatever budget. I just wouldn't use
it for sites with complex business logic, but let's face it, most websites,
even the big ones, are hardly rocket-science in that respect.

What I love most is the dynamic of the PHP community. For instance, when RoR
arrived on the scene, the response wasn't to dis RoR or run scared, but more
like "that's so cool, let's see if we can bring PHP to that level". And there
is more sharing of knowledge and experience (and code) going on inside the
PHP-community then any other developer community I know.

More then any development platform I know, PHP is alive and constantly
developing, but still as easy to deploy and easy to learn as ever.

~~~
jules
The only thing that's really good about PHP is the easy deployment. You just
upload your files to your server and it works. The language is very crappy, so
this easy deployment only outweighs the extra development effort up to a
point. I'd recommend against it for sites that take more than two days of
work. With services like Heroku, deployment with Rails may have become as easy
as deployment with PHP.

~~~
0x44
Actually, since mod_rails (Phusion Passenger) was released, that's a solved
problem for RoR.

------
thaumaturgy
Ruby and Python seem to be the current preferred languages.

I've used PHP for a while -- a few years -- and haven't developed a particular
loathing for it. That's saying something, since I'm disgusted by most of the
tools I'm forced to use.

It's certainly capable enough and isn't hard to use. It's also more
ubiquitous, and therefore arguably more portable, than Ruby or Python,
although dealing with differences between PHP versions is a pretty royal pain.

Pretty much any reasonably skilled programmer can do a job in PHP without too
much trouble. You'll get more cred for using Python or Ruby though.

~~~
pistoriusp
Also, Python and Ruby developers earn a bit more.

Here are the average salaries for permanent jobs over the last 3 months
according to <http://itjobwatch.co.uk>:

Python: £45,282

Django: £42,326

RoR: £41,204

Ruby: £39,897

PHP: £33,004

~~~
sanswork
There are also a lot fewer Python, Ruby and Django jobs than PHP jobs there so
you would expect to see more low/entry level PHP jobs in there pulling the
average down.

~~~
pistoriusp
You're absolutely correct. They have a maximum and minimum averages, but I
don't know how they work them out, so I'm not going to post them.

Number of salaries quoted for the past 3 months: PHP: 5283

RoR: 454

Django: 46

Thanks for pointing that out.

------
swombat
PHP is a brilliant language for small to medium-small sites.

Since most medium-small sites have an irrepressible tendency to grow into
medium and even large sites, I'd stay away from PHP for anything other than a
quick and simple site.

Ruby and Python are much more sustainable in the medium term and even the long
term, and just as quick to throw applications together. Sure, they won't last
forever, and eventually you may have to rewrite critical bits in another
language, but in the meantime it works to release something quickly and keep
improving it for a few years.

Daniel

~~~
wehriam
Are you speaking in terms of traffic? Several very large sites run on PHP
(Facebook comes to mind) while few run on Ruby (I think Twitter tops the
list).

~~~
alex_c
_I think Twitter tops the list_

<http://rails100.pbwiki.com/>

------
markbao
It's strange that nobody has mentioned that Yahoo! uses PHP to power a lot of
their software, and it obviously scales very well if you know what you're
doing.

They also remarked that they are looking into using Symfony framework in their
software.

~~~
ardit33
I wouldn't consider Yahoo the pinacle of software engineering, or a hotbed for
inovation. For a company of their size, they are not releasing any
groundbreaking features, or anything too advanced, and they are obviously
trailing google by a big margin.

Facebook and Digg are two other notable mention of php usage. Both are
handling very high traffic loads ok (not spectacular), and I know that
facebook is using a lot of C/C++ and some Java on the backend. The main reason
that they are php is b/c it was the better choice for the founders, to do
something quick at the time (2004-2005).

Ruby on Rails was not even out, and Python didn't have great and simple
frameworks with simple learning curve.

So, at the time the two sensible choices were Java or. Php. A great question
would be: If facebook or digg had to redo everything from the beginning, would
have still chosen php?

~~~
dimitry
Y! handles more traffic than Facebook and Digg combined and it uses primarily
PHP.

Why compare Y!'s stock performance to their underlying technology? Makes no
sense.

------
mdasen
PHP gives you more slack than any other language. . .

which is just enough rope to hang yourself with.

To be honest, part of it will depend on your style and part of it will depend
on your discipline.

I'm a fan of Python. PHP is not my style. I like one way of doing things. I
like namespaces. I don't like all the extra syntax that I feel is useless
({};$).

But that's just me personally. Many people hate python for those reasons -
it's constraining.

Objectively, PHP allows you to do what you want easily. The only problem is
that taking those shortcuts can come back to bite you later. If you
appropriately use include(), make sure to template out design, and avoid some
of those oh-so-irresistible hacky things, you'll be fine. Digg has done well
with PHP.

The problem is that it's hard to know exactly where you're screwing up
sometimes. For example, in python, every name used in a python source was
defined either in that file or in one of the imports. That makes it trivial to
figure out why that "I can't find that name" error is occurring. With PHP,
that name could be meant to be included 10 files back. They simply all carry
over.

So, is PHP bad? I personally think it is, but I'm a little conservative an
authoritarian when it comes to programming rather than PHP's more loose style.
Can PHP's style help you? Yes.

------
kogir
PHP is the VBScript of the open source world. It's available on almost every
web host, and it seems to be what beginners learn first. While I'm sure it's
possible to write things in a safe and mantainable way, most code examples you
see will be from beginners and will have problems with the OWASP top 10. You
can't look to the built in libraries for inspiration beacuse they're usually
poorly designed. Just because there have been success stories in a language
(cold fusion and myspace, php and facebook) doesn't mean it's right for you.
It took me one website and only 1000 lines of code to decide against PHP. If
you've used it longer and like it, it's probably fine.

~~~
fish
Code samples: <http://www.aspvphp.com/>

------
generalk
I currently do a lot of work in PHP, and although it isn't my favorite
language to work with (braindead built-in library, for one), it's hard to
argue with the results we get.

For the good of your soul, use a framework. We currently like Zend Framework,
but I've heard good things about CakePHP and Symfony. If you stick with the
framework and follow a sane MVC strategy you'll fix most of the problems
you'll have using PHP as an HTML templating language.

~~~
wenbert
I would recommend Zend Framework. I have had issues with Code Igniter. All the
workarounds and unexpected stuff frustrated me - I think not only me but other
users as well - that is why I think there is a fork: <http://kohanaphp.org>
... By the looks of it, I would recommend Kohana instead of Code Igniter.
Either way, I am not so sure about the future of CI. That is why I choose Zend
Framework.

~~~
neovive
The proper link to the KohanaPHP project is: <http://kohanaphp.com>. I've been
using Kohana for the past few months and it is major improvement over other
PHP MVC frameworks. It utilizes the OOP functionality in PHP5 to make
structured PHP web development much easier and elegant. If you are looking for
a new PHP framework, you should definitely consider Kohana. You could even
integrate with Zend Framework classes if needed.

------
thorax
We do a lot of work in PHP, but wouldn't even consider it if it wasn't for
clean MVC frameworks like Code Igniter.

To be honest, it doesn't feel much like PHP on the average bit of coding. It
feels like a "real" language most of the time because of the framework. They
have one of the best user guides I've ever run into (click Table of Contents
at top): <http://codeigniter.com/user_guide/>

~~~
JoelSutherland
I can second this. We use PHP along with a modern framework and love it.
Deployment is easy and PHP is so widespread that you can count on a script
existing to handle almost any little problem you face.

Granted there are times that its inconsistent library and lack of language
features can become annoying. If we're discussing languages alone, PHP is
certainly lacking.

With projects like mod_rails on the horizon and programmers trending away from
PHP hopefully we soon won't need to choose between a solid language and super-
simple deployment process.

------
jdavid
i believe that every language has its perks, and PHP has quite a few. as far
as back-ends go, there are a few types -xml/json webservices -low memory
application servers(blogs, shopping sites, etc..) -high memory application
servers(data mining, indexing, processing, game servers)

i think php is a great low memory solution, when you get into higher memory
loads for the app to process, you do not want to reload everything back in to
ram for each request. php is single threaded per request, and as such you
don't have access to sockets, or other event based activities on the server
side.

i agree with the statement in general, that you should go with what you know
to be the most efficient language for the task.

------
frankus
Having dealt with a lot of really awful PHP in my programming career
(including some of my earlier stuff), it tends to unfairly taint my view of
the language.

It's not terrible, but I've found that the clunky syntax for slightly more
advanced stuff (e.g. anonymous blocks) really discourages some labor-saving
and repetition-avoiding coding practices that a language like Ruby encourages.

It's a really good fit for small-scale sites with well-defined requirements.
But it requires some well-thought-out conventions to scale well, the sort of
stuff you can't come up with unless you've done it wrong a couple of times
yourself. Unless you borrow someone else's work by using one of the frameworks
out there.

------
kajecounterhack
PHP is the lazy man language. Sure, its messy and has bad convention. It gives
you bad habits unless you use a framework...

But then of course we should all take a step back and realize that Facebook is
built on PHP, haha.

------
blader
Go for the framework that lets you develop quicker. The truth is that there's
no framework on earth that has solved the 'scaling' problem for you. Anyone
who says '<framework x> doesn't scale' in all probability has never scaled
anything.

Scaling isn't even a real, real problem you need to worry about until you're a
top 1000 site at minimum, or > 10MM page views a day. At numbers past that, no
framework is going to magically solve your database partitioning problems.

------
lux
PHP simply requires discipline, which unfortunately many people in the PHP
world lack due to its initial target audience. Provided you find real hackers
and not just designer-turned-coder types, PHP is totally workable.

Mind you, when you're getting into the more functional side of Ruby or Python,
PHP starts to show its limits as a language. But it's still fast to code in
and to do so well if you know what you're doing.

------
cardmagic
<http://us3.php.net/manual/en/ref.array.php>

PHP's standard library is not object oriented

75 array functions

47 of them start with array_

28 do not

Out of the 28 that do not, you have such greats as: usort, sort, rsort, asort,
arsort, krsort, uksort, uasort

Nuf said.

------
andr
PHP is my preference for web development. However, you can do anything with
any language. The part that has the most influence on how easy or hard it is
usually the framework, not the language.

On that note, I am tired of articles comparing PHP to Rails. It's like
comparing a Honda to the metal used to build another car.

------
chuchurocka
i've been using it for all of my websites for about 6 years. It's robust
enough to do just about anything. it's just close enough to see C to be
familiar and just different enough to slightly irk you. I'm getting to ready
to roll out my first Ruby site though.

------
subwindow
I used PHP heavily for a few years (~70% PHP, 20% perl, 10% Java), and enjoyed
it for awhile. However, it seems like it is impossible to create clean and
well-divided code in PHP. This weighed on me heavily, as I had two 10,000 line
projects that I was the sole maintainer for. Even if you managed to create
well-structured code, it was always very... ugly (too many unnecessary symbols
$, ->, etc). It wasn't much fun to work in every day.

I'm using Ruby now and I would never go back.

Here's my rough order of language preference for server-side languages that I
have experience in: Ruby > Python > C# > PHP > Perl > Visual Basic > Java > C

------
simonw
It's a fine backend language for a small to medium sized website, but you need
to be aware that at a certain size (in terms of complexity of the application
you are building) you'll often find yourself fighting against the language.
That's not to say you can't build large applications in PHP, just that you
need a great deal of discipline to do so. You'll either need to adopt one of
the MVC frameworks (Symfony for example) or roll your own. A lot of the
features in the framework you chose will be workarounds for limitations in PHP
itself (such as its lack of decent namespacing and poorly designed database
access primitives).

~~~
ssharp
Yeah, it's perfect for your little side projects that will never grow or have
lots of traffic. You know, like Facebook.

~~~
simonw
Quoting myself: "That's not to say you can't build large applications in PHP,
just that you need a great deal of discipline to do so."

------
bprater
I'm not sure if this is a troll question. Elaborate on why you are asking. You
are asking: "what do you think of pudding" instead of "hey, I'm having a
dinner party and can't decide between apple pie and pudding, help me!"

~~~
amrithk
Well, we have used PHP extensively until now. We have gotten more disciplined
in designing code, compartmentalizing it into classes, documenting the code
etc.

However, I recently read an article on YC about how many startups go through a
phase debating about which language an application should be built on. We did
not give this much thought as we saw a few prominent websites like facebook
use PHP and we thought PHP seemed to be a pretty scalable language. Plus, with
support for OOP (as of PHP 5), PHP seemed to be a pretty good choice.

I am interested in evaluating if we made the right decision

------
norbert
I build absolutely everything on the top of PHP and the WACT framework. The
latter ensures that my code stays maintainable and well-organized. It also
emphasizes the use of design patterns. I'd never switch to anything else when
it comes to web development and I'd have left the industry if there was no
WACT. That's why I became one of its core contributors.

------
jdroid
I use PHP for basic stuff where I don't care much about performance or anyone
else maintaining it. It's installed on pretty much every web host and it's
easy enough to whip stuff up in. I haven't done a big web site in a long time,
but I can't imagine using anything other than Python for it.

------
davidw
I have a lot of respect for PHP, for having made web programming accessible to
people who otherwise would have struggled with something like Java.

However, I never want to use it again myself. I'm tired of digging through
horrible code written by people without a clue.

------
wenbert
Bottom line is: PHP can get the job done (cheap and fast) and scales pretty
well. I have been using Zend Framework for almost a year now - with the
release of 1.5, I recommend it above anything else (other PHP MVC Framework).

------
amrithk
Thats interesting. What is it about Phyton that makes it attractive?

~~~
simonw
It's a significantly better programming language; I don't think you'll be able
to find anyone who knows both PHP and Python and will disagree with that
statement. PHP is a very simple language with built-in features for web
application development. Python is an advanced, multi-paradigm general purpose
language that has evolved over more than a decade.

Here are a few Python language features that I seriously miss when I'm working
in PHP:

\- Modules and namespaces! This is the feature that initially drove me away
from PHP.

\- List comprehensions (let you construct a new list based on an old list in a
one-liner)

\- Built in iterator support (easy "for item in collection" support for many
different types of collection)

\- First class functions and closures (so you can treat your functions as
data)

Those are just four off the top of my head. If you haven't looked at Python
before (but already know how to program) I suggest taking a look at
<http://diveintopython.org/> which is a free online book.

~~~
norbert
Not to take a stand, just FYI: PHP5 has built-in iterator support now and PHP
5.3 includes namespace support as well (TBR this month).

~~~
apgwoz
But, PHP5's iterator is broken. The only way you can use it is in a foreach
loop. In Python, iterators can be used with any iterative construct.

Namespace support in PHP never really bothered me, but I've occasionally run
into problems with name clashes with built in functions. It'll be welcomed
anyway for sure.

------
tlrobinson
If it's the right tool for the job then use it.

Our app is nearly entirely client side, with a little server side PHP glue.
Something like Rails would be overkill.

------
ryanagraves
I'll admit, I'm a rookie. I've spent a few months now learning and writing
PHP...is my effort in vain? Should I ditch PHP and dive into Ruby with a Rails
framework?

~~~
crowbar
I don't think your effort's in vain. If you like it, keep at it. When you feel
confident in your knowledge on the language, you can then choose to move on
and experiment with other things. Same for any language, really.

Myself, I'm just now getting started into Ruby on Rails. I finally figured out
a project to get me interested in learning the Rails part of it. I just need
to get cracking.

------
LKM
Requries programmers with good security background.

------
eru
From what I have heard: If you can stand PHP - you can make it work.

I just do not like to code in the language.

------
senthil_rajasek
amrithk, what type of website are you thinking of building ? Your question
gives me as little clue as, "what language should I use to write software???

------
amrithk
Its been informative learning about your experiences. What do you mean by
frameworks? Something like a backend scripting language, a templating tool
(like Smarty or PHPTal), etc?

~~~
wenbert
I think he means MVC (Model-View-Controller) Frameworks. These things are so
hot nowadays... If your site is structured well, then you wouldn't have to use
templating engines like Smarty (god these things are so annoying)...

------
athloi
I prefer Perl

------
rbanffy
A hack, but not in a good way?

/me ducks

