
I Like PHP - haasted
http://beust.com/weblog/2011/08/09/i-like-php/
======
chc
_"I don’t even bother writing tests for most of the PHP I write (obviously, I
would be a bit more thorough if this code were destined to be used in a more
mission critical web site). Not writing tests is not the only software taboo
that I break when I write PHP: I happily mix up presentation and logic all the
time. That’s just how PHP is supposed to work"_

And this is why everybody else hates PHP. It tempts you to write bad code, and
so most people working in the language end up doing so. I have to periodically
stop myself when I'm writing PHP and make sure I'm not falling into bad
habits. It's possible to write good code in PHP, and I know some people who
do, but the pull to write sphpghetti is too strong for most. And there is no
real corresponding benefit (aside from "noobs who don't care about code
quality can still write programs") arising from the design choices that cause
this.

~~~
slindsey
Can you please provide me a resource to learn how to fully separate the code
from the markup? I learned web development on ColdFusion then switched to PHP.
I certainly understand separation of content from design (HTML to CSS) but I
honestly have no idea how to do web development without mixing markup (HTML)
with the actual programming.

I've done a little C and Java web stuff where my code printed HTML output -
ugly. CFML and PHP mingle HTML and code together - also ugly, but better. I
can't fathom any way NOT to mix them but would love to have some resources to
see what I'm missing. I know there needs to be something better. Thanks.

~~~
lhnz
Have a play around with a framework such as Symfony [1]. That's the most
natural way of learning a better style of PHP web development.

[1] <http://www.symfony-project.org/>

~~~
eropple
Any particular reason you're linking to Symfony instead of Symfony2? I find
the latter so much easier to read and work with it's not even funny.

~~~
wildmXranat
I'm not sure about that claim. I've been working with SF for years and tried
SF2 during early beta and I don't think it's that clear cut. Then again, I
don't care that much so - carry on

~~~
FuzzyDunlop
The doc's fairly incomplete and requires you to actually browse through all
the separate libraries that comprise the standard distro to even understand
what you can use and where. It being OOP-tastic and brimming with interfaces
and namespacing is great, but it is far from friendly to Symfony newbies.

Feels like you have to know Symfony 1 to understand what 2 is trying to do
really. I wouldn't recommend it as a good intro to MVC.

------
freshhawk
There's a regular stream of "defending PHP" posts but they all seem to miss
the point.

No one bashes PHP because it _can't_ do these things, or that it isn't easy.
People bash PHP because there are objectively better languages and platforms
out there and objectively bad decisions made by those guiding the PHP
language.

If you want to defend PHP in any meaningful way then you can't just list
things that can be done easily in almost every semi-modern web ecosystem, but
actually compare it to the other alternatives and identify when it's the right
choice. It's harder but it leads to a blog post that might actually benefit
readers.

~~~
skrebbel
> _If you want to defend PHP in any meaningful way then you can't just list
> things that can be done easily in almost every semi-modern web ecosystem_

Did you ever read Python's documentation? Or Ruby's? Or Java's?

Show me _one_ popular web programming language which has a full page, up to
date, with examples and user comments and version incompatibility info, per
_function_.

Of course, it's just one point and I otherwise agree with your comment, but
it's one _hell_ of an advantage.

~~~
dchest
> user comments

Ha-ha-ha. You're kidding, right?

Check strlen: <http://www.php.net/manual/en/function.strlen.php>

Comments:

1\. Comment about how PHP converts types. "Conclusion: The values are
converted to string before check the lenght."

2\. Comment from a novice user who posted a solution to the problem of
subtracting the number of spaces in string from its length.

3\. Comment about someone who thought that there was a bug in strlen, but it
actually was a documented difference in behavior between two minor versions of
PHP.

4\. Comment about counting characters in UTF-8 encoded string by decoding it
to some other one-byte encoding.

5\. Comment about counting characters in UTF-8. Actually, the whole new
function.

6\. Reminder that \r\n are actually two bytes! "If I had thought of this
starting out, I would have saved myself several hours of trouble trying to get
php to cut a message to the same length that my auxiliary javascript
validation imposed on it."

7\. Benchmarks for different UTF-8 strlen implementations.

8\. Complaint about another comment, which suggested the function to count
characters in UTF-8 strings that didn't work. And the "proper" solution using
_regular expressions_.

...

~~~
46Bit
It may just be a side effect of PHP's problems, but even the wrong comments
tend to be extremely useful when you run into something weird when coding. Of
course it's always more fun to bash people & programming languages, so maybe
I'll just join in: that bloody Ruby API reference lacks any comments from
users who might have noticed something that's causing a strange bug in my
script.

~~~
dadads
As much as I love Ruby, I have to say that the Ruby docs website is shit. No
search bar (unlike the PHP docs website).

~~~
DuoSRX
Agreed. I use <http://rdoc.info/stdlib/core/1.9.2/frames> which has search and
a nice UI.

------
Peaker
> PHP is exactly like C. Either you like both or you don’t like either, there
> is no claim you can make about PHP that can’t be made about C as well, and
> vice versa

* C is fast and has tight resource control

* C is portable

* C has a transitive (==) operator

...

~~~
dpcan
I sort-of felt like this comment was added in his post to get the blood
boiling a little.

I love his other points about PHP (as I too like PHP), but I felt this was one
of those bold statements that was a little sensational and attention grabbing
at best. I too find it pretty far fetched.

~~~
ZoFreX
I honestly don't intend this in a mean way (I mostly code in PHP at present),
but if you loved his other points you might want to delve a little deeper. PHP
is a good enough language, but a lot of what he is saying is either incorrect,
poor form, or championing solutions to problems that simply don't exist in
other languages.

------
tomelders
From the comments: "PHP is great for its purpose. Quick scripts that generate
web content. It’s even OK for small applications. But just like C, PHP is
lousy for the medium to large. Any software project with a duration in months
or greater that is entirely in PHP is going to be painful."

Like Facebook? Or Wordpress? Or Digg?

PHP aint perfect, but it's demonstrably suitable for medium to large projects.

~~~
tvon
There is little indication that Facebook isn't painful to deal with compared
to a functionally identical version of Facebook built in another
language/platform. Because someone did it and is profiting from it does not
mean they could not have done it better.

~~~
carbonica
Considering Facebook uses Haskell to automate changes to their PHP codebase,
I'd imagine PHP isn't doing them any favors.

~~~
__rkaup__
I heard about that tool. Can you tell us more about what it does?

~~~
antoncohen
It is called lex-pass [1], it does syntax aware transformations of PHP. Like
sed, but specifically for PHP. There is a video that mentions it briefly at
2:00 min [2].

[1] <https://github.com/facebook/lex-pass> [2] <http://www.vimeo.com/6699769>

------
kingkilr
> PHP is like C

In all the bad ways, and none of the good ones.

~~~
peteretep
I like MJD's quote the best: "Like C without the speed, like Perl without the
toolbox"

------
phatbyte
My first web language was PHP, I started working with it 12 years ago. Back
then you didn't have Rails, Django, ORM, unit testing (in web dev that is),
and javascript was looked as a language to just show popups and have
confirm()'s before submitting forms.

If you wanted to connect to a MySQL, you have to do it all by yourself, you
need to create a database, tables, PKs, connect to database, execute RAW mysql
queries, and so on. Form validation ? Yeah right. Back then the include_once()
or require() were amazing for separating code. But all in all that mades us
learn how things work internally, how HTTP requests work, how SQL works, even
why CSRF or XSS and SQL injections are executed.

Yes, the code was shitty, it was all over the place, but we learned how a web
app works internally.

And yet, most developers I know who coded PHP back then are amazing developers
today in any web language or framework. Why ?

Because most of them learned doing things the hard way. We had to understand
how HTTP requests works, how SQL works, etc..etc.. because we didn't have the
magic of rails, or any helper for any framework.

In these 12 years, web development as grown, a lot, and for the better, I'm
currently learning Rails, and I've already done a project with Django and
Node.JS . I liked them a lot and they are amazingly well done, I just wished
PHP was more OO like ruby or python.

However, I laugh at these new Rail/Django developers that joke about PHP code.
Most of them start coding jumping immediately into a framework. I bet that
most of then couldn't create a simple MVC framework, ORM from scratch, hell,
even a simple security CSRF would be a pain without "gem install <whatever>".

You see kids, PHP was like our first GF or our first car, where we tried
stuff, made us cry (in a sense), and helped us grow and mature as developers,
for those who wanted to grow that is. Now you have lots of languages for web
dev, but back then PHP was the thing.

I still believe that PHP is a very cool language if done correctly, I wished
tho, that it should be rewritten to be more OO.

But if one thing I learned from all of these years is that, it's the developer
who makes quality code, not the language. Unless that is, you are using a
framework who basically demands you to do things the way it wants, and puts a
lot for magic so you don't bother with "boring" stuff. But in the end of the
day it's not your code, it's theirs.

So my advice for new dev is, forget frameworks, and learn the hardcore way,
then pickup a framework you love and go with it, either PHP, Ruby, Python or
whatever.

~~~
relix
I don't think it's a good idea to advice newbies to learn the hardcore way.
I'm exactly like you, started with PHP, had to do everything manually, etc...
except I have a different opinion.

The reason you and I and all the others like us put in so much effort in
solving problems in PHP like CSRF, XSS and SQLI was because we were passionate
enough to learn about that and then implement solutions for it.

Developers who don't care about security measures like that - they're the ones
who store plaintext passwords, still - won't care either way, no matter if
they're using Rails or PHP. Frameworks like Rails solves it for them, but if
it weren't for Rails, their apps would have all these security problems, and
they would only be addressed once disaster strikes.

Those that do care will be passionate about their work. They are the ones that
read up on XSS and CSRF out of interest, not necessity. I'm sure they look at
the generated HTML source once in a while, and then wonder why they add that
token there. Using Rails, newbies are exposed to the solutions from the start,
encouraging them to learn about it. As a PHP newbie, you're never exposed to
the problem or the solution, until you start reading about security on your
own or you get into trouble.

~~~
ircmaxell
The point was that a good programmer is a good programmer regardless of their
tools. And a bad programmer will always be a bad programmer no matter how much
their tools do for them.

Spend time becoming a good programmer, and you'll be better off in the long
run. If you don't want to spend that time, go find another profession...

------
asifjamil
"There is nothing more exciting than modifying a file, hitting Refresh on your
browser and seeing the result right away"

I think this feature is definitely useful, but you can virtually do the same
thing in other languages with templating engines.

~~~
tvon
With additional setup, yes, but PHP has a fast development cycle out-of-the-
box which I think is significant.

~~~
mseebach
This mind-bendingly important. In 1999, you could download one single
installer on Windows, run it and with literally no further configuration you'd
be writing PHP on an Apache/MySQL stack. No other environment even came close
at the time and for a long time following.

~~~
j_col
This is still the main reason why I use PHP: the development cycle is just so
fast, and if you are experienced enough to write good code without anyone
holding your hand, you can do great work in PHP in a much shorter period of
time when compared to most other platforms (at least the ones I've tried).

When people criticise the PHP _language_ I think they really miss the point:
it is the PHP _platform_ that is really powerful because of:

1\. The shared nothing architecture (it really helps you scale).

2\. The rapid development cycle.

3\. The portability (Apache, IIS, nginx, persistent in-memory interpreters via
PHP-FPM...).

4\. The huge amount of native C extensions providing amazing functionality.

Sure the _language_ has warts, but who cares when the _platform_ is this
powerful?

~~~
ericd
Yep. And compared to Rails, something like mod_php is just so much faster and
less resource hungry, it hurts. I use both regularly in production, and
scaling the PHP side is almost trivial compared to the rails side.

~~~
boyter
Sorry to nitpick but that isn't scaling. Unless I can add double the number of
machines and double or almost double the capability, and keep doing so to
thousands of machine your application doesn't scale.

In the case of web applications all tend to scale equally well as you can just
add another web server. Its the database that causes the scale issues.

~~~
ericd
Scaling vertically is still a valid strategy, and is scaling. Not every
company needs to be able to scale to the moon, and if they don't, it's a poor
use of time to focus too much on architecting for scalability.

With a lightweight PHP framework and a sensibly written app, you can stick to
one machine for much longer than you can with Rails, and after that, it will
require a fraction of the number of app servers. Beyond that, app processing
time is generally much lower without all of that cruft, so you don't need to
do as much caching, etc. to get a snappy webpage.

~~~
boyter
Maybe its just me but I don't consider "scaling up" as scaling. In my mind
scaling means running on more then one machine.

Don't get me wrong though, throwing a bigger hardware box at a problem is a
totally viable solution to most problems, up-to a point.

------
vandahm
Where I work, we've standardized on PHP and I have no choice but to use it. It
isn't as bad as people say that is! Our organization's product is a large
application written in object-oriented PHP with unit tests for every method of
every class. As a team, we use continuous integration and have regular code
reviews to promote quality. We've done some things that we're not proud of,
but on the whole our codebase is pretty clean and elegant, and at the end of
the day I'm almost always proud of the work I've done.

What worries me about PHP is that innovative ideas don't appear to be coming
from the PHP community. They come from Python, or Ruby, or Erlang, or Java
projects and are copied by PHP developers afterwards. I worry there's a risk
that PHP is being left behind as the developers who solve new and challenging
problems turn to other languages.

Furthermore -- and this is just my sense of how things are where I live --
while it's possible (and not even difficult) to write quality PHP code, it
seems to be difficult to find developers who care about quality. My manager
complains about this constantly and I'm inclined to believe him since, when I
was a freelance developer, I saw tons of PHP code that was simply and
unambiguously terrible. Conversely, a developer who wants to write quality
code in PHP has to look pretty hard to find a PHP shop that recognizes quality
and values it. I suppose that these issues aren't tied to a particular
language, but they seem more pronounced with PHP.

------
rjknight
PHP's greatest strength is that it doesn't require OO. Seriously, for most
simple _web application_ tasks (and even some complicated ones) OO adds more
confusion than it removes, and I say this as someone who certainly sees the
value in OO for complex apps.

Most web apps are ultimately more like shell scripts or console applications
than desktop/mobile applications. It's no coincidence that most of the former
are written in C or C-like scripting languages, and most of the latter are
written in OO languages running on .NET or Java. Your basic operations are
"print some stuff", "read from a file or database" and various sorting,
slicing and text-processing tasks inbetween, all of which are done well by
PHP, Perl, C and so forth. ActiveRecord, TableDataGateway etc. are great
patterns for data access, but sometimes mysql_query("SELECT foo FROM bar WHERE
x = y") is just so much simpler that it becomes the better option.

The lack of OO makes PHP's documentation much more browseable, and makes code
more readable in certain situations. If I look at your code and I see a
function I don't know, I just google it. If I see a method invocation on an
object, I need to figure out the type of the object (not easy in a dynamic
language) and google the combination of class and method name, which often
fails to return a result (has anyone ever managed to find anything useful in
the Zend Framework docs?). PHP isn't the only data point for this argument - I
think it's probably why Drupal handily beats ZF, Symfony etc. in terms of
popularity, despite the superior OO architecture of the latter. You can google
pretty much any API function and get an accurate result, which you just can't
do with ZF (which lacks documentation at the method level, and what
documentation that exists is buried in some Doxygen-based site which is made
impervious to search by the use of frames). I'm also reminded of Linus's
argument against OO in the Linux kernel - when you're all about the patch
files, you need clear function names to understand what's going on without
massive amounts of context. Drupal's rate of contributions probably exceeds
that of other frameworks for similar reasons.

Of course, this bias against OO is also what makes PHP a bad choice for
certain things, and this is why plenty of devs hate it. I honestly don't know
if, in the final analysis, this makes PHP a good or bad choice. It probably
depends too much on the problem you're trying to solve for there to be a
simple answer.

~~~
phamilton
A tricycles greatest strength is that it doesn't require balancing on two
wheels.

For those who can't ride a bicycle, tricycles are great.

Once you understand how to use a framework/language like RoR, I don't see how
PHP is more useful (unless you have size constraints).
ActiveRecord::Base.connection.execute("SELECT foo from bar where x = y") is
just as simple as mysql_query("SELECT foo FROM bar WHERE x = y"), and you get
the benefit of abstracting away the database in database.yml so you can run it
in different environments.

~~~
Domenic_S
the db_query() function in drupal also does that abstracting.

~~~
phamilton
Yes, but the OP was talking about framework-less simple projects.

------
mtogo
This comment is almost better than the blog post itself:

> _But just like C, PHP is lousy for the medium to large. Any software project
> with a duration in months or greater that is entirely in PHP is going to be
> painful._

Yeah, C is terrible for medium to large projects like, say, Linux.

~~~
pavpanchekha
C is one of the few languages Linux _can_ be written in. That doesn't mean
it's the best for the job.

------
PedroCandeias
I'm just glad we're at this point where there are so many quality languages
and frameworks available that we can fuss over which one is best. That is all
I'm going to say on the subject.

------
yuvipanda
> I write PHP code very sporadically

Explains it. PHP is fine if you jump in, write a few lines, and then don't
ever have to maintain it yourself. Woe to the guy who does have to maintain
it.

~~~
cedricbeust
Absolutely, and I'm sorry if my article didn't carry this point across.

I would never use PHP for anything big/complex, my post was mostly in response
to the universal sneering and mocking that PHP always gets. I think it's
unjustified.

Since I only modify my web sites a few times a year, I am pretty sure that I
would be much more reluctant making these modifications on a RoR app than a
PHP one.

------
acabal
I like PHP because it's got a C-like syntax, which is a personal preference of
mine. I also like it because it exposes the nuts-and-bolts of web development
without any fuss, unlike, say, ASP.NET (though last I touched that was 3 years
ago so doubtless things have changed since), and that it has a basic
templating system built in, and that it's easy to install and deploy to.

It definitely is deeply flawed for many reasons, which is why I'm still
looking for my "white unicorn" language: one with a C-like syntax, no fancy
templating or ORM magic (just let me print() html), foss, easy to deploy, and
with an established community and searchable "recipes" online.

Lots of languages fit some of those criteria, but I haven't found one that
fits them all.

~~~
ZeSmith
For ASP.NET, indeed, WebForms can be a bit violent since it's essentially an
abstraction that tries, with mixed sucess, to make you forget you're writing
for the Web.

ASP.NET MVC, which came out 2 years ago, is much closer to RoR and other
similar frameworks, and is a better abstraction in my opinion.

~~~
MatthewPhillips
I don't think Microsoft is even still developing WebForms (last release is
April 2010). Too many aspx sites are written in the old version of WebForms
which turned the html output into a horrible and ugly mess. MVC3 is pretty
much just as good as RoR or any other mvc framework about outputting clean
html.

------
tiwilliam
Stopped reading when I came to:

"Sometimes, I don’t even bother editing the files locally and then
transferring them: I ssh to my server and modify the files live."

------
jessedhillon
More than providing any defense or justification for the use of PHP, this
article greatly bolsters the opinion that PHP is for noobs.

------
kayoone
You can do anything web related with PHP, it might not be the coolest kid in
town but it gets every job done pretty well in the space it has been designed
for. Use a framework like symfony and large scale applications with decent
design are no problem at all in PHP. Same is true for Python, Ruby etc though,
so just use what suits you best. Comparing it to C ? Dunno, completely
different animals. I wouldnt do web dev in C, but i also wouldnt do graphics
programming in PHP. Just because they both are not designed with OO at the
core doesnt mean they are exactly the same.

------
aidenn0
My observations for the popularity of PHP are this:

1) It's old. You're alternatives to PHP 12 years ago are all bad. The most
popular alternative was perl CGI scripts.

2) Since it's templated, it feels more like markup . Someone with absolutely
no programming background can go: HTML -> HTML with a javascript "onclick"
handler pasted from the web -> HTML with a bit of PHP pasted from the web ->
writing my first original PHP code

------
rickmb
PHP's one great strength is that it can be effectively used in a very wide
range of applications. But doing that well requires using the language in ways
suited to that purpose.

The problem with people "defending" PHP is that they often only use PHP for a
very specific purpose, and describe PHP from that perspective.

Hacking quick and dirty procedural scripts, writing something like WordPress
plugins or developing "enterprise" applications with frameworks like Symfony
or Zend are entirely different ways of using PHP, usually done by entirely
different kind of developers.

The unmaintainable crap PHP is infamous for occurs when less than mediocre
developers only familiar with one approach apply those limited skills to a
project that requires a completely different approach.

What the author describes is not "how PHP is supposed to work". It's just one
of many ways PHP can work. (And certainly not my way of using it.)

~~~
eropple
Agreed. The big problem with PHP, as I see it, is that you have to be already
very very good with PHP to write a safe, well-performing application in it.
The steps you may take along the way to get there may be very scary,
especially if it involves other people paying you to do it.

------
jarrett
The biggest problem with PHP isn't anything built into the language itself,
but rather the culture of mediocrity/naivety surrounding it.

As at least one other commenter has said, there are disciplined and skilled
PHP programmers. If only they were the majority! Sadly, for the PHP ecosystem,
a few good apples don't unspoil the bunch.

Here are a few ways PHP's bad culture manifests itself.

1\. Cargo culting

The web is filled with questionable recipes for doing this or that in PHP.
I've observed a strong tendency of PHP programmers to approach every possible
addition of functionality like this: 1) Google search; 2) find source code
that supposedly does what's needed; 3) paste that source code in without
understanding it or thoughtfully evaluating its appropriateness.

I'm all for learning by reading other people's code. I'm even OK with pasting
code when you understand it fully. But cargo culting is bad, and it seems
rampant in the PHP world.

<http://en.wikipedia.org/wiki/Cargo_cult_programming>

2\. Lack of architecture

PHP applications often lack a coherent architecture. It's a typical mistake of
new programmers--one that I made many times--to think just enough about
architecture to accomplish the task immediately at hand. Naturally, this comes
back to bite you when you want to extend your code's capabilities. I see this
all the time in PHP applications.

Consider Wordpress. Its API is a random, ad-hoc mess of global functions.
Things that should logically be exposed as objects aren't (like posts, for
example). The API for retrieving content is different depending on whether
you're in the mysterious "Loop" or not. And so on. A more detailed analysis of
the lack of architecture in Wordpress can be found here:

[http://www.phpvs.net/2009/12/08/an-exercise-in-wordpress-
int...](http://www.phpvs.net/2009/12/08/an-exercise-in-wordpress-integration-
or-why-wordpress-sucks/)

3\. Frankenstein coding

Similar to cargo culting, Frankenstein coding is when you cobble together an
application from a bunch of off-the-shelf plugins or modules. This is a common
practice in the Drupal world specifically, but it applies to a greater or
lesser extent in much of the PHP ecosystem.

There are two major problems with this approach. First, the chunks of
functionality you download are not likely to match your needs perfectly, so
you're forced to make due with software that's almost what you want. Second,
the code quality of these modules is often abysmal, and that means security
flaws, among other problems.

Sadly, many PHP developers seem perfectly content with this. Even worse, they
do this for clients, who get a semi-functional end product at bargain basement
prices. That practice gives me a cheap, sleezy vibe, and it doesn't help my
impression of the overall PHP ecosystem.

The language itself is so-so in my opinion--not good enough to be my go-to
language, but not so terrible I'd refuse to work with it. But somehow,
probably due to the language's accessibility, the PHP ecosystem seems to have
been swamped by coders who know just enough to get by. And that's my real
problem with PHP.

~~~
pacemkr
I can't disagree with much of what you said. However, you are being too
critical of Drupal.

"the chunks of functionality you download are not likely to match your needs
perfectly, so you're forced to make due with software that's almost what you
want"

Drupal starts you off with 80% of the product functionally complete (!), for
free, and leaves you with the spit and polish jar to squeak out the other 20.
I find that this 80/20 rule is true for even very complex products. The lazy
developer will never do that remaining 20%; this says nothing about Drupal.

You can name a function according to a convention and reach into any part of
Drupal, or a contributed module, to pull that specific string that you need.
I'll be blasphemous and say that not having to instantiate half a dozen
objects just to dive through their properties to achieve the same result -- as
you would likely have to in a "proper," purely OO CMS -- is very refreshing.
The result is the same and the code is readable.

"Code quality is often abysmal."

True for one out of ten new modules that I encounter; and you are free not to
use those modules. The heavy weights: CCK, Views, etc. are excellent.

~~~
jarrett
"Drupal starts you off with 80% of the product functionally complete (!), for
free, and leaves you with the spit and polish jar to squeak out the other 20.
I find that this 80/20 rule is true for even very complex products. The lazy
developer will never do that remaining 20%; this says nothing about Drupal."

I agree with that statement 100%. I don't think Drupal forces you to build a
half-finished site with ten security holes. My problem is that lots of people
do anyway. I don't necessarily blame Drupal for this phenomenon. I just think
it's emblematic of a culture of quick and dirty coding that ultimately makes
life harder for professionals and our clients.

------
nerd_in_rage
PHP sucks as a language, but honestly, it's a LOT less painful to develop a
working web app in PHP than Java, Python, and just about everything else.

Why? There's no deployment issues. There's no waiting for my app server to
restart, no delay while a change is detected, etc. You edit a file, click
refresh.

Flame away.

------
leeoniya
PHP is fast to develop with, but its inconsistency and quirks make it a real
PITA to work with quite often. a good summary of the main crap is outlined
well at <http://www.phpsadness.com/>

------
alanh
Keep in mind that perhaps a majority of wordpress.org sites that have been
around for a year or more have been hacked in some fashion at some point, and
that the reason is because PHP encourages the kind of terrible code and
unsafe-by-default environments that make this possible.

 _Edit_ For example, I am thinking of how various templating languages,
including Jinja2 (for Python) default to auto-escaping strings you're echoing,
but with PHP, you by default have to explicitly think about it and call
`htmlentities($x, ENT_QUOTES, 'UTF-8')` all the time.

~~~
pale_rider
WordPress sites get hacked because the owner fails to update the platform or
install 3rd party scripts/plugins without any sort of logical research.

This can be said about any platform, regardless of the language.

~~~
alanh
> _WordPress sites get hacked because the owner fails to update the platform_

Why are the updates even necessary? If you are still on Rails 2.3.8, you
aren’t getting hacked just because you didn’t move to Rails 3 yet. But the
situation with Wordpress & its ecosystem seems waaay less secure by default.

> _This can be said about any platform, regardless of the language._

Not to the same degree, no sir.

~~~
pale_rider
Last time I checked Rails was not a content management system.

A fair comparison would be Drupal, Joomla, vBullentin - anything of that
nature - which all regularly release updates.

~~~
alanh
Those are all PHP based and would seem to prove the point.

------
yid
From TFA:

> * I have yet to see this kind of universal support for any other language
> than PHP. Not even Ruby on Rails, let alone Java, is available on mainstream
> providers, thereby validating the claim I made five years ago that Ruby on
> Rails won’t become mainstream (I regularly receive emails about this article
> asking me this question, and I keep responding “Nope, still not
> mainstream”).*

If your provider doesn't support Ruby, you need to get yourself a $20/month
Linode box. If Linode and a $20/month price point isn't mainstream, I don't
know what is.

~~~
Ixiaus
You can do cheaper than that - WebFaction will give you an $8 a month shared
hosting account and you can run _anything_ you want! They have a really cool
automated setup system for more involved projects like
Django/Pyramid/Sinatra/Rails and lots of others.

~~~
yid
...which leads me to think that the poster is confusing "mainstream" with
"GoDaddy".

~~~
cedricbeust
I'm not.

I'm using a fairly "non-noob" ISP (ssh access, crontab, etc...) and they still
don't give me access to much more than PHP. I can install Java but I can't
even run it as a CGI because of the HTTP request memory constraints they
impose. This is pretty standard, I don't blame them for doing this, and I
would go with a VPS if actually needed all this.

Same for Ruby on Rails, obviously.

~~~
yid
I fail to see why "my ISP doesn't give me Ruby" --> "Ruby isn't mainstream".

To my downvoter, here's a list of "mainstream" providers, at the Godaddy-
level, and language support:

Dreamhost: RoR, PHP, Perl, Python [1]

Godaddy @ $8/month: PHP, Perl, Python, RoR [2]

a2Hosting @ $3/month: PHP, Perl, Ruby, Python

That seems pretty mainstream to me.

[1] <http://beta.dreamhost.com/web-hosting/> [2]
<http://www.godaddy.com/hosting/web-hosting.aspx> [3]
<http://www.a2hosting.com/services/web-hosting/>

------
brendoncrawford
_> Either you like both or you don’t like either, there is no claim you can
make about PHP that can’t be made about C as well_

Except that PHP is terrible for systems programming?

~~~
j_col
And PHP has super-aggressive garbage collection and C has none. And C compiles
to machine code and PHP compiles to optcode. And...wait a second, why are we
comparing this two unrelated technologies again?

------
mbrzuzy
Is PHP that much worse where it's worth it to jump onto the ruby ship?

I'm just starting to code one of my current projects, but in PHP. Should I
consider ruby instead?

~~~
adambard
Here is some PHP code:

$x = "0"; if(!$x){ echo "0 is false"; }

If you understand why it's crazy that PHP prints "0 is false" when you execute
that, you're probably better off jumping ship now. If you don't, you'll
probably appreciate the low barrier to entry for PHP more than any benefit
you'd gain.

~~~
NathanKP
I understand why it prints zero is false, and personally I feel that it makes
perfect sense. Indeed I approve of it. The fact that strings can be evaluated
as numbers is great for accepting input from GET or POST because it means that
there is no need to worry about explicitly casting strings to numbers.

Of course, input type validation is still important, and if a variable input
by the user is supposed to be numeric, that is why there is the is_numeric()
function to validate the type of a variable.

But once I've used is_numeric() and know that the string is numeric why should
I bother with an explicit strtoint call? I feel that this feature of PHP if
used correctly takes away complexity and repetition related to converting
strings to integers.

In a realistic project the framework for your app should have a layer between
user input and your code anyway. At this layer it will be validating that
input from the user is of the correct type anyway, and once that variable
passes the is_numeric() test the layer can easily cast that input string to an
int so that it is the right type for JSON encoded objects or any other output
from PHP for other languages that needs to have specific types.

Once again, if PHP is used properly, with a decent code architecture this
feature of PHP is not a problem.

~~~
wtetzner
Perl does the same thing with type coercion, and "0" in Perl is false.
However, the thing that Perl does that PHP doesn't is have different operators
for strings and numbers.

Don't get me wrong, I think conflating strings and numbers is a bad idea, but
if you're going to conflate strings and numbers, then having separate
operators is the right thing to do.

~~~
NathanKP
I am not very familiar with Perl. When you say different operators for strings
and numbers are you referring to something similar to PHP's === operator for
which "1"===true would be a false statement?

~~~
chromatic
Perl's numeric equivalence operator is ==, while its string equality operator
is eq. Perl's operators are monomorphic that way.

------
scelerat
I submit that PHP's popularity has much more to do with mod_php and its
ubiquity across cheap web hosts than any intrinsic merits as a language.

As someone who made a good living for many years by building stuff with PHP...
I couldn't get away from it fast enough. Rails+Heroku is the new PHP, if you
want a batteries-included web framework and easy hosting.

Not rhetorical: does anyone here use PHP for starting new projects?

~~~
j_col
Yes, in fact all of my new projects are in PHP unless I'm absolutely forced to
use something else (and I say this as someone with years of Java experience
and some Ruby experience).

------
perlgeek
"there is no claim you can make about PHP that can’t be made about C as well,
and vice versa."

What about hundreds or thousands of inconsistently named built-in functions?

C doesn't really have built-in functions, just a standard library that you
don't have to load if you don't like it.

~~~
roel_v
That's at best semantic nit-picking. You cannot write a useful C program
without using the standard library or re-implementing (parts of) its
functionality yourself. If for some reason having functions available that you
don't use bothers you, you can still easily disable most of them by not
loading any extensions; and if it's really a big issue to have the 'standard'
functions in php available, you can compile php to not include them. If this
is the best example of why php isn't like C, they are actually very similar...

------
tambourine_man
The core of C is small enough that you can fit it in your head.

PHP has so many functions that it's almost impossible to write it without
googling php.net, etc.

Not that this matters so much, Google is fast and omnipresent, but in that
sense they are definitively not alike.

~~~
ZoFreX
Almost impossible? Pop quiz: The case-insensitive version of "strpos" is
"stripos", what is the case-insensitive version of "strcmp"?

~~~
simonw
I'm guessing it's stricmp... However off the top of my head I have absolutely
no idea what the argument order and return values for any of those four
functions will be without looking them up.

~~~
ZoFreX
_buzzer sound_ I'm sorry, the answer we were looking for was "strcasecmp"

(Sorry if the level of levity is considered inappropriate, but humour is a
level 4 defence mechanism and the only way I can remain sane in the face of
such things)

------
rb2k_
> Not even Ruby on Rails, let alone Java, is available on mainstream providers

Just picking a few of the "big" ones:

dreamhost.com: supports RoR

hostgator.com: supports RoR

bluehost.com: supports ROR

hostmonster.com: supports RoR

godaddy.com: partially supports RoR (fastcgi)

I guess that is simply not true anymore

------
rick888
One of the reasons I like PHP is that it still lets you get to a lower level
of coding. Many of the newer languages and frameworks that have become popular
in the past couple of years abstract things such as database connectivity away
(Django is a good example of this) and it makes it difficult to optimize
queries effectively without hacking onto the framework.

~~~
rick888
Wow, It's pretty apparent that there are a lot of young programmers here on
HN. I was just stating my opinion and I got downvoted because I talked bad
about your precious frameworks.

~~~
adambard
The comparison between PHP and frameworks isn't valid. Writing PHP on a
framework probably abstracts away SQL too, just like writing CGI in Python
gives you lower-level control.

~~~
rick888
When frameworks are the popular alternative to PHP (RoR,Django,etc), it is
valid.

Are we also not allowed to talk about RoR when it comes to a discussion about
PHP alternatives?

~~~
docgnome
It's a bit comparing apples to oranges. If you were comparing say Cake or Zend
to RoR and Django then it would be a reasonable comparison.

~~~
ericd
It's not really apples and oranges - writing a website in raw Ruby is not a
very feasible or popular option, whereas writing a website in raw PHP is. It
is valid to compare writing a site in PHP and writing a website in Rails. It
is also valid to compare writing one in Cake vs. RoR, as well as Cake vs. raw
PHP (or a custom PHP framework, which is what raw PHP inevitably becomes in a
sufficiently large project).

------
plq
me too, i like php. it's a decent templating language with some very advanced
features. it even supports namespaces!

~~~
pornel
It's an XSS-prone templating language, as the default correct syntax for
outputting variables is:

    
    
         <?php echo htmlspecialchars($value, ENT_QUOTES);?> 
    

which is far from encouraging safe best practices.

PHP namespaces aren't any better: <http://pornel.net/phpns>

~~~
shiflett
Actually, you should also always indicate the character encoding, for reasons
I explain here:

<http://shiflett.org/blog/2005/dec/google-xss-example>

~~~
pornel
Yes, declaration is necessary, but not in the htmlspecialchars() call if
you're using ASCII-superset encoding (and you really should declare UTF-8,
never UTF-7).

------
iterative
You know who used php? Hitler.

------
rogeriopvl
Gotta love these "My tool is bigger than yours" discussions...

------
dillon
You say if you make one assumption about C, you have to say the same about
PHP. Well, PHP is academic, C is not. C is fast, PHP is not. I would only have
agreed with your post if it were PHP and C++. C++ is academic and it's not
slow but it is slower.

You also say that you either like both PHP and C, or you like neither. Well
what about Lua, Python... or any other embed-able language? Most Python
programmers would say they don't like PHP but love C, because the languages
work well together, same with PERL as well. You could say that you either like
both C++ and PHP or you like none. Maybe, because PHP can compile to C++ to
become extremely fast, which is why Facebook and Yahoo both use PHP because it
can be fast and it is well documented. It should not be compared to C though.

(Note: I contradict myself, PHP by itself is slow. PHP is not fast whatsoever.
C++ is a low level language which is the only reason why it's fast and I think
it's awesome that PHP can compile to C++. I'm in no way against PHP and I'm
not encouraging people to stray away from the language. I was just pointing a
simple error in this post.)

~~~
masklinn
> PHP is academic

Uh... could you explain how you arrived to this assertion? Because as far as I
can see, PHP definitely is not academic. The bloody thing started as a hodge-
podge collection of Perl scripts, and to this day it still does not have
anything even remotely close to a formal grammar. A language in which
`foo()[1];` is a syntax error even though `$a = foo(); $a[1];` is valid code
most definitely is not academic.

~~~
jrockway
Actually, it's parsed with a rather simple yacc grammar. The reason why
foo()[1] doesn't work is because it's a bad programming language, not because
it doesn't have a grammar. It has one and it says not to parse that :)

