

Avoid PHP trap - alexk
http://id28.blogspot.com/

======
randallsquared
PHP has a lot of functions that actually take away lots of pain, but you have
to know they're there. If only this fellow had found implode(), he wouldn't
have needed to write enumerate().

I was a PHP hater for years, but I find that for certain types of problems, it
really is the right solution.

[Edit, later: and you can (and should) paper over some of his other
complaints. PHP isn't a great language qua language, but it has such great
penetration that it almost doesn't matter.]

~~~
jamesbritt
"I was a PHP hater for years, but I find that for certain types of problems,
it really is the right solution."

Can you give some examples of those certain types of problems?

~~~
randallsquared
Sure. Social networking sites like the one in my user profile. Pretty much any
site where the building of the site would be fairly trivial in any language,
and scaling is the problem: with PHP, you can start it on any cheap host and
port it in minutes to better servers, because you don't have to worry so much
about setup. If the idea itself is innovative, but there's nothing interesting
about the code that the site runs on, PHP is an excellent candidate.

I've built sites (some for clients, some of my own) in a bunch of languages,
and there's a certain amount of tradeoff between setup/installation and actual
coding. For whatever reason, languages which are more fun or more productive
to code in require more setup time, and are likely to be already installed on
a random new server almost exactly in reverse proportion with how
fun/productive they are. It's eerie.

~~~
jrockway
_Pretty much any site where the building of the site would be fairly trivial
in any language, and scaling is the problem: with PHP, you can start it on any
cheap host and port it in minutes to better servers, because you don't have to
worry so much about setup._

Aren't most PHP apps dependent on weird php.ini settings?

And anyway, the "real" langauges are equally easy to deploy. Get yourself a
$20 slicehost account (to start with), add two lines to apache's config to
enable FastCGI, then just copy your app up to that server. That's all there is
to deploying Perl, Ruby, and Python these days.

With Perl and Catalyst, I can "make catalyst_par" and get a file that contains
the entire application; including the version of Perl I am developing with.
That way I know for sure it will work when I copy it to production. (Yes, this
means I have to use the same architecture for both development and deployment.
I do.)

~~~
randallsquared
Weird php.ini settings can almost always still go in the directory with the
php files, so just copying the directory automagically makes everything work
right. Some settings don't work this way, of course, but I'm not sure which
those would be, offhand.

If you're using Python, for example, you're probably also using some
framework... for years I used Webware for Python, and more recently web.py.
Both require careful attention to get working in a convenient fashion, in my
opinion.

------
rob
Seems like blog spam, but this post has said nothing new from all of the other
'PHP sucks' posts, so I have no idea why you decided to make yet another one.

I like PHP since it is so easy to deploy and it can be used for anything from
a simple two page website to a full-blown web application. Being written in
PHP also means that you are not limited in hosting.

If you're a startup creating a single web app, then fine, use Python with
mod_wsgi or Rails and five mongrel servers. But if you're creating basic CRUD
websites, especially more than one, then there is nothing wrong with PHP. I
can fit dozens of low-traffic websites on a $20/mo 256MB RAM server using
Apache and mod_php; try doing that with Rails.

As I said, if I was going to focus on a single _web app_ with its own
dedicated server, then I would definitely look at Python and mod_wsgi, but
since I create a lot of 'smaller' websites (nothing too complex), it is much
less of a hassle using PHP since I can fit all of them nicely on a single,
cheap server.

~~~
alexk
Blog spam? What does it mean?

~~~
michaelneale
I think it means a blog post which kind of reads like it was written by a
person, but is really a mushing together of paragraphs and sentences from
other posts in order to get some traffic and serve ads.

------
andreyf
PHP's equivalent of lambda is great for a nice laugh, though:

<http://us2.php.net/create_function>

~~~
jawngee
There are a variety of patches available that give you anonymous functions, as
well as closures. You need to seek it out and compile. But, I guess from your
laughter, that shouldn't be an issue for you since you've got the CS thing
down.

<http://www.opendogs.org/pub/php-5.3dev-071228a.patch>

You'll have to backpatch it for 5.2.6 but it took all of an afternoon for us
to do.

At massify, we run a patched version of PHP that provides all of the above.

~~~
andreyf
I'd love to see that patch merged into PHP, but even then, it will take some
time to change the habits of people using this in libraries, frameworks, etc.

------
coglethorpe
PHP was seductive, for me at least.

I wrote my first startup in PHP - No Smarty, no Cake, no Pear, just PHP. And
it worked!

PHP leads the developer down the easy path then locks them into a big
codebase. Yes, it has it's problems, but in the end it works or can be trained
to work.

That said, I'm seriously thinking of Python/Django or Rails for my next
project.

------
mojuba
It is not at all obvious that {...} is better than, say, array(...) for a
language that has operator braces {}. PHP's array constructs are a little
verbose, but they are visually distinguishable and thus are not that bad at
all.

{...} as an array/dictionary literal makes more sense in a language like
Python, where braces are not used otherwise.

~~~
randallsquared
If creating a new language that looked like PHP/C/Java/etc, you could use {}
for both blocks and arrays (and assoc arrays, like PHP) by making blocks a
special case of arrays, conceptually. Then {0; 1; 2; 3;} would be an array of
four elements, and as a bonus it would free up [] for something else. :)

~~~
mojuba
Like in C or Perl, OK, but that makes both unreadable for humans rather than
for compilers, that's what I'm saying. So the reasons behind PHP's array()
construct are not trivial.

------
samosman
"Pick one, and stick with it"

Best advice i got.

------
edw519
The day I settled on PHP was the day I was finally able to focus on the guts
on my project, not on the infostructure. Let me explain...

I used to use what I thought was the "best tool for the job".
Javascript/HTML/CSS for the client, another language for the server, another
DBMS, and a separate server. And I spent half of my time trying to figure out
why one thing didn't work with another. It was never anything big, but just
bad enough to slow me down (performance, scaling, security).

Then a friend asked why I was messing with all that. He said to just download
an Apache/PHP/MySql stack, install it, and forget about it. So I did.

Sure I hate the syntax, especially the dollar signs starting variable names,
but I have never had a problem getting it to do exactly what I wanted. If I
ever had a question, there were a hundred places to turn for help. And I never
had to worry about one technology working with another.

I've always been a non-conformist when it came to tech, probably to get an
edge on everyone else. But I learned the hard way, there's a time to conform
and a time to be a maverick. I'd rather conform with a standard platform and
"do my own thing" with my apps.

------
neovive
PHP has many good lightweight frameworks that put the fun back into building
web apps. CodeIgniter and KohanaPHP are especially lightweight. It isn't much
fun coding web apps in raw Ruby, Python or any language.

------
Jax
Oh boy!

If you say php sucks, then go get some sleep and think again.

Thats the easiest language any noob can start web development with. Lots of
libraries and resources. Just do a search for 'web development tutorial' and
you'll find that every 10th good tutorial will be about php. Python is easier
than php, but every cheap host supports php.

And another fact: you can even create desktop apps with php. There a GTK
extension to php. Google PHP-GTK for more.

------
agentbleu
More nonsense about PHP.

Hey go get sexy and python yourself.

