LWN.net Logo

PHP is a love child

PHP is a love child

Posted Dec 8, 2008 22:09 UTC (Mon) by pr1268 (subscriber, #24648)
Parent article: PHP 5.2.7 withdrawn

BASH, C, C++, and Perl all got together and had a love child... and called it PHP.

Hey, it's not often that PHP is discussed here at LWN, and I just wanted to share my thoughts on it. ;-)

Consider that you can write code comments in PHP in the same fashion as four other programming languages, not to mention echo(), print(), and printf() all do the same thing. I especially like how print() returns an int whose value is always 1. Useless.

The weird thing I remember in a college class on compilers was when someone chose to implement his project compiler in PHP (the instructor had given us free reign on choosing what language in which to code our compiler). It can be done (considering that PHP is Turing complete), and this student did so, but the instructor was skeptical.


(Log in to post comments)

PHP has some unique properties?

Posted Dec 9, 2008 8:03 UTC (Tue) by khim (subscriber, #9252) [Link]

What other language have comparison operator which is not gives you at least partial order. Adds nice flavour to the language - sort() gets some properties from random(), etc...

Homework: fill the blanks.
$a = ___;
$b = ___;
$c = ___;
if ($a < $b && $b < $c && $c < $a) {
  echo("PHP is unpredictable language!\n");
}

PHP has some unique properties?

Posted Dec 9, 2008 12:54 UTC (Tue) by nix (subscriber, #2304) [Link]

SQL (and its bastard children like PgSql, PL/SQL et al) have this lovely characteristic too if you're dealing with NULLs.

(For that matter, IEEE754 requires these semantics when comparing floating point numbers if one of the numbers in the comparison is a NaN.)

Good answer

Posted Dec 9, 2008 13:12 UTC (Tue) by khim (subscriber, #9252) [Link]

That's two cases I knew as well. But in both SQL and C disaster is localized: in SQL you can use "NOT NULL" mark to make sure there will be no NULL in the column, in C you can avoid floating point altogether (and floating point numbers are anomany in many other reasons). In PHP there are no simple rule to avoid this.

Actually all languages can be marked as "nice", "bad, but unavoidable" and "bad AND avoidable". Python and Java are first (they do have problems but overral they are "nice"), C/SQL/JavaScript are second (have nasty surprises but almost impossible to avoid in practice) and PHP is in the last category.

Good answer

Posted Dec 10, 2008 11:17 UTC (Wed) by ballombe (subscriber, #9523) [Link]

Why special casing C over this ? The IEEE754 standard is not C specific, other languages support it (C++, etc) and have the exact same issue.

In the end it is more of a hardware issue (if you want to use the FPU of your machine in a portable way, you have to deal with IEEE754 semantic).

PHP is a love child

Posted Dec 11, 2008 9:57 UTC (Thu) by __alex (subscriber, #38036) [Link]

If only PHP was half as good as any of those languages. (Well, maybe not Bash script ;)

I would *much* rather write a web app in C++ than PHP. At least C++ is expressive. PHP is all of the convultion and bizarre corner cases with none of the tools to help you cope with it.

PHP is a love child

Posted Dec 11, 2008 17:54 UTC (Thu) by elanthis (guest, #6227) [Link]

Are you serious? PHP has a crappy security record, but I can't imagine anyone managing to write a complex and secure C++ web app and still having their sanity intact afterward. C++ is one of my favorite languages (yes, really), but part of knowing a language is knowing its strengths and weaknesses... and C++ is quite a poor choice for a wide variety of tasks, including Web development.

PHP is not really _that_ bad. Its language design has a number of flaws, sure, but so does Python. And C++. And Java. And TCL. And Perl. And Lua. And JavaScript. And Haskell. And so on.

Most of what makes PHP suck is the people who use it. It is the server-side equivalent of JavaScript. JavaScript is actually a pretty nice language if you have half a clue on how to use it properly; most JavaScript in the wild blows donkey nuts because the people writing it are untrained and untalented as developers. All those non-programmers who end up moving to server-side programming usually end up working with PHP, so you end up with just a huge amount of horrendous PHP code in the wild. So you end up with wildly popular applications like osCommerce or Wordpress that look like they were coded by slightly retarded baboons or practically standard libraries like Smarty (whose code makes me throw up a little in my mouth whenever I have to look at it).

I know that it is quite possible -- easy, even -- to write clean, elegant, readable, maintainable, efficient code in PHP. I do it almost every day. Some of my colleagues do it almost every day. But for each of those skilled colleagues, I have to work with 5 interns who write code that I often end up having to rewrite (and end up making it 10x smaller, 10x faster, and quite a bit more readable). You can see what happens when those intern-quality programmers start to think that they're good; look at the comments in the PHP manual. Every standard function ends up with a ton of comments with "my PHP implementation of the function" which are buggy, inefficient, or just ugly... and I can't even figure out why the hell someone would post a PHP reimplementation of a f***ing built-in function documented right on that very page!

Yes, PHP has its warts. Its standard library is kind of a mess and needs a major cleanup effort. Its missing a few super-useful features, like first-class functions, namespaces/packages, and named function parameters. It's got a few ill-advised hacks, most of which were there because PHP was originally designed as a template language instead of as a true server-side programming language. These are being cleaned up, slowly. PHP6 will have a lot of that cruft fixed, although it still has a long way to go (maybe by PHP7) before things are within an arm's reach of perfection. Let PHP7 be to PHP what Python3 was to Python, and I think PHP would lose a lot of its stigma.

I guess the overall summary of my ranting and rambling is that languages do not suck; programmers suck.

PHP is a love child

Posted Dec 11, 2008 21:28 UTC (Thu) by kruemelmo (subscriber, #8279) [Link]

"Most of what makes PHP suck is the people who use it."

Absolutely, but still a skilled, experienced programmer will not choose php for a new web application if she/he has the choice.

Moritz

If not PHP, then what?

Posted Dec 11, 2008 21:53 UTC (Thu) by pr1268 (subscriber, #24648) [Link]

Absolutely, but still a skilled, experienced programmer will not choose php for a new web application if she/he has the choice.

If not PHP, then what? ASP .Net?1 Perl? Python? Ruby?2

1 I know several people who write Web apps in ASP .Net simply because their employer chose that for them. They'd much rather use various FOSS (or otherwise Unix-ish) tools, but it's simply too hard to convince their bosses to change (or look for other work).

2 It's already been discussed here and elsewhere how PHP isn't any worse than Perl, Python, or Ruby with respect to creating "good" (or bad) code. Your mileage (and attitude) may vary depending on the nature of the Web app.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds