views:

686

answers:

9

I recently had my first encounter with PHP (5) through a Drupal application for a client. There was certainly nothing difficult about the experience (documentation is good for instance), but I never had a moment where I thought, "that's really clever!", or "wow this is fun to use!" Moreover, I couldn't accurately predict how functions were going to be named, or ascertain a guiding principle to follow.

This is in contrast to Ruby, for instance, where everything is an object, methods are predictable and pseudo-polymorphic, and blocks are a joy to use (to name a few examples). Other language highlights for contrast: Python's list comprehensions change the way you think about iteration, C brings you back to the hardware with it's pointers and bit operations, javascript is surprisingly wonderful with its nameless functions and advanced suppport for hashes, and even SQL in its crustiness forces you to appreciate your data and think about it relationally.

So with that in mind, what are the highlights of php? And what is the overall design philosophy of the language? I know php doesn't enjoy a great reputation overall, but I've always heard that that was a perception problem due to the large amount of non-professional developers banging out copy and paste code.

EDIT:

Alright, so the consensus is that PHP is the monkey-wrench of web programmers. I can accept that. I was just looking for a insight, but I guess I already had it. I certainly do appreciate mod_php/libphp for instance. And I was able to get my application out the door in two weeks with no prior php experience, so I guess that also speaks for itself.

Thanks for the posts.

+17  A: 

From the php web site:

PHP is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly.

In other words, there isn't really a design philosophy: It's a mix and mash of ideas to get a job done (obviously inherited from Perl, hehe).

Nerdling
So you're saying it inherited its tight conceptualization and clear vision from Perl?
David Thornley
@David: Yes, in much the same way humans inherited their wings and gills from the primates.
Pesto
+2  A: 

Regarding function naming/conventions there certainly isn't any design philosophy behind it.
Unless you regard inconsistency as a design philosophy :)

cherouvim
+9  A: 

PHP's emphasis is on getting the job done, quickly, not cleverness. That's not to say that you cam't write nice, clean, object-oriented code in PHP. I think that where most PHP programmers go wrong is in thinking that because you can embed PHP in HTML, that you must do so. My own PHP code is strongly object oriented and contains no embedded code at all (apart from the initial page).

And as you point out, PHP is very well documented, which is more than you can say for many of its competitors.

anon
My experience with code that gets the job done quickly is that everything winds up taking longer.
David Thornley
Well, we must disagree. For example, I find that writing C++ code as opposed to C takes abot one tenth of the time and is about 10 x more reliable and maintainable.
anon
That's unfortunate. I've seen (and written) code quickly and well upon occasion (IMHO). :D Some of it in PHP. Roughly in the same proportion as code that's been written slowly and poorly vs. slowly and well.
le dorfier
I was unclear. Tools and methodologies designed to get the job done, quickly, without cleverness, frighten me. Presumably you can write good PHP code, just like I can write good Perl code, but I can't take your description as a recommendation.
David Thornley
Why is "cleverness" such a good thing?
anon
+10  A: 

The design philosophy of PHP:

D'oh!

stesch
+1, I was thinking something like "none"
RSolberg
+1 because PHP is really the only language in the history of languages that I would say is just an unredeemable POS
temp2290
+1, I would call the philosophy is 'any retard can code now'
zalew
+2  A: 

From a PHP book I have:

PHP is an open source project of the Apache Software Founation and it's the most popular Apache web server add-on module, with around 53% of the Apache HTTP servers having PHP capabilities. PHP is particularly suited to web database applications because of its integration tools for the Web and database environments. In particular, the flexibility of embedding scripts in HTML pages permits easy integration of HTML presentation and code. The database tier integration support is also excellent, with more than 15 libraries available to interact with almost all popular database servers.

It goes on to talk about the following advantages:

  • Open source
  • Flexible for integration with HTML
  • Suited to complex projects
  • Fast at running scripts
  • Platform- and operating-system portable
  • A community effort

I know this doesn't really answer your question, but maybe it provides a little higher-level glance at what PHP is all about.

From: Hugh E. Williams & David Lane. Web Database Applications with PHP and MySQL. 2nd Edition.

Cory Larson
PHP is not currently a project of the Apache Software Foundation.
Bill Karwin
True story -- the book is from 2004.
Cory Larson
+1  A: 

PHP was a server-side include system for HTML documents with a Perl syntax. It's been trying to outrun its heritage ever since.

ashawley
+5  A: 

What you have to remember is that PHP was a revolution. At the time PHP was created by Rasmus Lerdorf there was really no alternatives for dynamic sites. Well there was CGI-GATEWAY (which php basically is) which involved writing your own C exe to serve pages - there was something called ASP but it was fairly rubbish back then and only ran on windows boxes which were very few and far between on the web.

You could say its reason to be or it design philosophy was that it was the first mass-market scripting language for the web. It wasn't so much designed as grown which is why it seems a bit of a mess, but it does the job.

Toby Allen
+1  A: 

Do what thou wilt

rektide
A: 

I think the good thing about php is that you can get up and running rather quickly and it is very friendly to beginners. The first language I learned was Java in school, so PHP was very easy to pickup. When I learned Java, it was hard to pickup the OO concepts the first time around and I didn't really understand completely. But since you don't need to use OO in PHP it is very easy for non-programmers to pickup learn the language basics and then be able to move on to learning objects.

I agree the language is kind of chaotic, but it does power sites like Facebook, Digg, and parts of Yahoo. Can't really say the same about Ruby (more specifically rails), with the exception of Twitter.

jimiyash