Slashdot Mirror


The PHP Anthology - Volume I, 'Foundations'

sympleko (Matt Leingang) writes "What a beautiful world anthology is. It comes from the Greek for a gathering of flowers, and in literature means a collection of works. Harry Fuecks, a very frequent contributor to the SitePoint community PHP forums, has gathered a bouquet of PHP best practices in a new book. The book comes in two volumes. The audience for Volume I, "Foundations," is the advanced beginner who's done one or two things in PHP, but you wants to know how to do more. Volume II, "Applications," is a design volume, mainly, and is good for people who have lots of experience with PHP but want to be better programmers. It's nice that the two volumes are separate; if you already know the syntax and mechanics of PHP you can buy Volume II and maximize d!/d$.*" Read on for Leingang's review of Volume I, and watch for his followup on Volume II. The PHP Anthology: Volume I: Foundations author Harry Fuecks pages 376 publisher SitePoint rating 7 reviewer Matthew Leingang ISBN 0957921853 summary Good start; for the real story read Volume II as well.

The book is very well-written, often using a question-and-answer heading style that makes searching the table of contents easy. In the preface, we already meet the first cool aspect of the book: lots of links to sites in the form of footnotes.** Yes, most books of this genre include links to web sites, but this way makes a couple of things clear: first, that there are lot of references, so you have many places to jump to for more information, and it's a sleeker text flow: embedding URLs in dead text makes line breaking hard and detracts from the flow of the language. As you read a page, you can note, "OK, that's an online resource," and keep reading without having to stumble over an incomprehensible URL.

Each volume has numerous code examples, and they're all on the book's web page to save you from transcribing. The web site is the best place also to buy the books; they're generally not available in stores.

Chapter 1: PHP Basics
These are the foundations of the book. Quick highlights:

How does one exactly RTFM? The author directs the novice to the PHP web site and explains what each part of the online manual corresponds to. But also, the coolest aspect of the PHP web site is its search-by-url feature. It looks up a function or language reference page, finds a set of likely matches, or just googles the site for you. Try it: http://php.net/array, http://php.net/sprintf, http://php.net/error.

How to understand error messages. Remember your first "cannot add header information -- headers already sent" error. Huh? Learn the difference between parse errors (what you wrote is not valid code), semantic errors (you're asking PHP to do something illegal), environment errors (PHP is not equipped to do what you want), and logic errors (PHP is happy but you're not). The last is particularly insidious (no E_PEBKAC level of reporting), but unit testing (see Volume II) gives you hope to find and fix those.

How to include. What is the difference between include and require (answer: require forces a fatal error if it can't find the file you want, while include only warns)?

How to write portable and reusable code There are hundreds of configuration directives, and using them can make one of your applications simpler. But some are to be used only with careful consideration. The magic_quotes_gpc directive, for instance, sounded like a good idea at the time it was developed. It automatically escapes user input so backslashes remain backslashes and not escape characters. A common use of this directive allowed you to insert user-supplied data directly into a database without checking to make sure any embedded quotes wouldn't create unintended SQL statements. While this does guard against SQL injection attacks, you could still end up with garbage in the database. So you still have to check user data to make sure it complies to your standards. This is easier to do before escaping magic characters, so it's better to wait until just before storage; then add all the backslashes you need. Nowadays it's considered good form to not rely on this directive and just use addslashes when you need it.

For maximal code reuse, consider object orientation. But there's a whole chapter on that...

Chapter 2: Object Oriented PHP
"Be lazy," the author writes; "Write good code." One of the ways to organize your code is through object-oriented programming. Most readers know the basic concepts of OOP, and are probably tired of the few over-simplified examples. Beyond that this chapter wants to get you to think OO, to "no longer think about long lists of tasks that a single script should accomplish; instead, [to] see programming as the putting together of a set of tools to which your script will delegate work."

I know my first PHP classes were just namespaced scripts. The attributes and methods weren't at all related. This chapter (as well as Chapter 7 of Volume II) helps you distinguish where your classes are and how they connect. One of the aids for this is the use of Unified Modeling Language (UML) class diagrams. These diagrams, which use boxes for classes and arrows for the relationships between them, are really cool programming and teaching tools that require no code!

Here I think the book's physical workflow got caught in a gap between major PHP releases. The cover says this book says "PHP5 ready," which is a bit of a misnomer because all the code examples and rules are all written for PHP4. Minor text mentioning how things are going to be different in PHP5 has been inserted. It's true that none of the OO code written here will break in PHP5, but there are major additions to PHP5 especially in the OO implementation (no more ampersands! actual private variables! Exceptions! Much, much more!). Still, the author makes the point that you the programmer may not be using PHP5 for a while (PHP 5.0.0 is only a few weeks old today), and that you shouldn't put off learning PHP until version 5 is agreed to be stable.

I've read the comments of PHP bashers, arguing that using it for OO programming is a waste of overhead. The author has heard that argument, too, and rebuts:

"What they forget to mention is the drastic increase in your performance that object oriented programming delivers. After all, fast programmers cost more than fast microprocessors!"

Hear, hear. RAM and disk space are commodities, while programmers are not (yet).

Chapter 3: PHP and MySQL
This goes beyond the simple HOWTO on connecting to a database. A suite of PHP classes is developed for database connections, querying, and result handling, not as much to use as for your "health"--i.e., to see a well-done class from start to finish. For your real applications, use a real, well-maintained and tested class such as those found in PEAR. This is another principle of good programming: Somebody has probably had the same problem you are having right now, and already solved it (also known as Ecclesiastes 1:9, "...there is nothing new under the sun.")

If you've done lots of SQL queries, you get to thinking that there's got to be a better way to access a database. In fact, you can build a layer of abstraction over the database connection layer to create interface classes to individual tables. This is called a persistence layer. For an implementation, see PEAR::DB_DataObject.

Any web programmer fears insecurity, and I don't mean self-doubt. The author weaves discussions of security into each chapter. For instance, you must be careful to guard against allowing users to seriously alter the nature of your SQL queries. Trust no user-supplied data! Also, this chapter gives a PHP-based solution for creating MySQL dumps.

Once you've got the data in the database, making sure users can find it is another problem. You can use LIKE relations in your queries to search field strings. The author shows how to use FULLTEXT indexes (a MySQL 4 feature) to assist in searching the entire table or any set of fields you like, all at once.

Chapter 4: Files
Sometimes databases are overkill for data storage, or you need to extract data from text files. The author gives several examples of uses of interacting with a local or remote file system. He explains:
  • how to slurp whole files into memory or to process them chunk-by-chunk.
  • how to use the PHP built-in functions to interface with the file system (so you can make a self-updating "Last updated: " item on your pages).
  • how to use .ini-style files to store configuration data -- a common configuration style which is much faster than keeping it in a RDBMS or XML file.
  • how to use FTP with PHP.
  • how to compress and decompress with tar through PHP.
  • how to send create a file and send it to your web user (custom files generated on-the-fly and ready for download!).

Again, the security threat is raised, and the author gives pointers on how to prevent from crackers getting you to execute their code by including one of their files rather than your own.

Chapter 5: Text Manipulation
When building dynamic web sites, being able to manipulate code is a must. You need to validate the data that users send to you, as well as guard against simple HTML error or malicious cross-site scripting (XSS) attacks. There are lots of built in functions (strip_tags to remove the HTML from a string), but using regular expressions you can validate and filter just about anything. You can reimplement a restricted set of markup tags a la BBCode, or set up a custom, easily-updated profanity filter.

Chapter 6: Dates and Times
Another real-world problem is formatting dates and times in a human-readable (and perhaps localizeable) way, and on the machine level manipulating dates correctly. Luckily these are all solved problems and PHP connects you to the C functions which do it. Whether you store dates as MySQL timestamps (e.g., 2004-08-03 20:07:00) or UNIX timestamps (1091578114 seconds since the epoch) is up to you, although if you use the former you'll probably have to convert to the latter at some point. Putting it all together you can create dynamic calendars where clicking on a day brings you to your appointments for that day. Another good use of date functions is a implementation of cron written entirely in PHP for those not on a unix platform.

Chapter 7: Images
Once you've mastered the art of producing HTML with PHP (developed even further in Chapter 9), you'll wonder what else can do. It turns out that PHP, using glue to the GD image library, can output images as well. You can generate thumbnails of your images to create galleries. You can watermark images with text to discourage stealing them. You can hide your images behind a PHP script that protects people other than you from linking directly to your images. And you can analyze data with enough charts and graphs to make Ross Perot ecstatic.

Chapter 8: Email
Contacting your users off-site is a must if you want them to come back. Furthermore, it's a nice way to register users by sending them links to an address they provide. PHP can send email natively using the mail function, but as always there are nice classes which jazz up the features. You can send HTML attachments (known by some as "spam", but we're not here to judge), even including the images in the mail. You can even use PHP as a replacement for procmail by parsing incoming mail and triggering actions based on headers.

Chapter 9: Web Page Elements
Eventually you get tired of writing HTML, and interweaving markup and presentation logic can give you a headache. Can't PHP be told to format the table the right way? Another solved problem! Displaying data in a table is a common task, and classes such as PEAR::HTML_Table can take a simple data structure and beautify it for you. Forms are another area in which PHP-generated code can save you time. You can also use PHP to produce "breadcrumbs" (there's one at the top of every slashdot page) and drop-down menus that show your users where in the hierarchy of information they are. Finally the author shows how to use apache's url_rewrite module to get those question marks, file extensions, and ampersands out of your URLS and sex them up. (You can also do this without url_rewrite, completely inside PHP, but using a custom error document and examining the path requested.)

Chapter 10: Error Handling
So you're all excited about your next web app, and you dive into coding, and something goes wrong. What then? This chapter is about errors. You can use the error_reporting function to customize which exceptions actually produce error messages, or create your own error messages that handle errors your own way. You can choose to log them in a database, send an e-mail to a coding team, and most importantly, recover gracefully so that your users don't see an error message. Not only is it unprofessional, it may reveal information about your program, file system, or database structure that can harm you.

Appendices
There are several good appendices, which tell you which configuration directives you're probably most interested in (the complete list you can get on PHP's web site), some common security breaches, and how to install PEAR, PHP's version of CPAN. My favorite appendix is the "Hosting Provider Checklist," a great reference for evaluating whether kewlhosting.com is going to give you the freedom and support you need to make a great hosted web site.

All in all, I liked this volume. Having read probably a dozen PHP books I wouldn't say it offers new information. But even though you know the plot, it's possible to enjoy a well-told story. See Volume II for heavier-duty ideas.

* My made-up calculus notation for "bang for your buck"
**Like this: http://books.slashdot.org/

In real life, Matthew Leingang is Preceptor in Mathematics at Harvard University. He promises to review any book sent to him for free, and sometimes actually does it. Slashdot welcomes readers' book reviews. To see your own review here, carefully read the book review guidelines, then visit the submission page.

114 comments

  1. resume is too good by theMerovingian · · Score: 5, Funny


    In real life, Matthew Leingang is Preceptor in Mathematics at Harvard University.

    If you're that in real life, what is there to pretend to be on slashdot?

    --
    "If you think you have things under control, you're not going fast enough." --Mario Andretti
    1. Re:resume is too good by DarkHelmet · · Score: 4, Funny
      If you're that in real life, what is there to pretend to be on slashdot?

      I dunno, how about The Merovingian :P

      --
      /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i
    2. Re:resume is too good by theMerovingian · · Score: 2, Funny


      Or a lawyer, I guess...

      --
      "If you think you have things under control, you're not going fast enough." --Mario Andretti
  2. Nice review, another one... by Walrusss · · Score: 1, Redundant

    Another of the hundreds (thousands ? whoa ! are you sure ?) of books on php/mysql... If I bought all of them, I'd be broke since a long time :-)

  3. Spelling and grammar by DarkHelmet · · Score: 3, Funny
    "What a beautiful world anthology is.

    All your base are belong to PHP?

    Or...

    All your spellcheckers are belong to us?

    --
    /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i
    1. Re:Spelling and grammar by WormholeFiend · · Score: 2, Funny

      At least he didnt mispell "Harry Fuecks".

    2. Re:Spelling and grammar by Anonymous Coward · · Score: 0

      Unfortunately, he did.

    3. Re:Spelling and grammar by Anonymous Coward · · Score: 0

      Actually he did and Mother Fucks is very annoyed her little Harry's name is being abused.

    4. Re:Spelling and grammar by Anonymous Coward · · Score: 0

      It would have passed through a spellcheck.

      Most of the morons who post like that either: 1) are in such a hurry to see their material posted; or 2) are just plain idiots.
      Unfortunately, when they are confronted, they just figure it's part of being in the technical culture.

    5. Re:Spelling and grammar by Bull999999 · · Score: 1

      All your spellcheckers are belong to us?

      Gosh, you are very demanding, aren't you? Do you expect us to start RTFA, too?

      --
      1f u c4n r34d th1s u r34lly n33d t0 g37 l41d
    6. Re:Spelling and grammar by Q2Serpent · · Score: 2, Funny

      But you misspelled "misspell" :)

    7. Re:Spelling and grammar by steinnes · · Score: 1

      There is nothing more amusing than browsing through the company CVS, and find entries like "Fixed a few speling erors"

  4. The PHP Anthology - Volume III by Anonymous Coward · · Score: 5, Funny

    B-side remixes and band commentary.

  5. Spellcheck anyone? by Petronius · · Score: 3, Funny

    it's a mad mad word.

    --
    there's no place like ~
    1. Re:Spellcheck anyone? by wankledot · · Score: 3, Funny

      The problem hear is that spell check would not have caught there error. Your right, though, its annoying.

      --
      My sig is blank, I typed this by hand.
    2. Re:Spellcheck anyone? by JabberWokky · · Score: 4, Funny
      The problem hear is that spell check would not have caught there error. Your right, though, its annoying.

      Ha! You did the same thing! Improper word choice. Your message should read:

      The problem hear is that spell check would not have caught there error. Your write, though, its annoying.

      --
      Evan

      --
      "$30 for the One True Ring. $10 each additional ring!" -- JRR "Bob" Tolkien
    3. Re:Spellcheck anyone? by Anonymous Coward · · Score: 2, Funny
      The problem hear is that spell check would not have caught there error. Your write, though, its annoying.

      Doofus. The problem is with the "Your".

      It should be:

      The problem hear is that spell cheque wood knot have cot there error. You're rite, though, its annoying.
    4. Re:Spellcheck anyone? by Anonymous Coward · · Score: 0

      and it should be their error

    5. Re:Spellcheck anyone? by r3m0t · · Score: 0

      there -> their, Your -> You're, its -> it's

      Yes, it is anoying! ;)

    6. Re:Spellcheck anyone? by Anonymous Coward · · Score: 0

      I think what he meant to say was:

      The problem ear is that spell check would not have caught that there error. Your rights, though, are annoying. :-)

    7. Re:Spellcheck anyone? by Anonymous Coward · · Score: 0
      Wrong again:

      The problem hear is that spell cheque wood knot have cot there error. Your rite, though, it's annoying.
    8. Re:Spellcheck anyone? by SamBeckett · · Score: 1

      You guys are all fucking wrong.

      The problem here is that spell check would not have caught their error.

      You're right, though, it's annoying. As annoying as fucktards like myself not getting the joke before hitting submit.

    9. Re:Spellcheck anyone? by Anonymous Coward · · Score: 0

      it's only ever means "it is" (or "it was"), therefore you have inserted one correct word into an otherwise incorrect sentence. If you're going for the wrong word for everything, then you really do want its.

  6. PHP is a Great Language by nycsubway · · Score: 4, Interesting

    PHP is one of the best languages I've come across. And I think a lot of it comes from the available library of functions. They're all very well organized, especially in the PHP manual.

    I learned PHP by reading the manual, but I found I didn't need a book because it all was very similar to Perl/C, etc.

    1. Re:PHP is a Great Language by johnnyb · · Score: 3, Informative

      I like the fact that you can just point your web browser to

      http://www.php.net/FUNCTIONNAME

      and get the documentation for that function.

      Perl has a lot more contextual tricks to help the programmer, but PHP is a lot nicer to beginners who don't want to worry about whether they are in scalar or list context, and what the present value of $_ might happen to be.

    2. Re:PHP is a Great Language by Anonymous Coward · · Score: 3, Insightful

      I like the fact that you can type

      perldoc -f FUNCTIONNAME

      and get documentation for that function.

      Wait...you mean every language has a function reference? Gosh.

      PHP is nice for beginners and a PITA to anyone who want to actually do something useful. The function reference routinely omits examples for advanced usage.

    3. Re:PHP is a Great Language by johnnyb · · Score: 1

      Viewing perldoc isn't quite the same as viewing a hyperlinked web page.

    4. Re:PHP is a Great Language by Fweeky · · Score: 4, Insightful
      "They're all very well organized"

      Are you kidding? Here's a small sample of string and type handling function names (about as standard library as it gets):
      gettype(), is_int(), strlen(), str_pad(), parse_str()
      Is is strfoo(), or str_foo, or foo_str() or foostr() or what? What it is is fairly well documented, but that's pretty much a requirement with an API as large and messy as PHP's.

      It is similar to Perl and C in some ways; that's not a positive note in my book though.

      Now, why hasn't Rails hit SlashDot yet?
    5. Re:PHP is a Great Language by Anonymous Coward · · Score: 0

      Finally! A language that has less respect for naming conventions than I do. If only they'd thrown in some sTr_fo0(), then I'd read this book hands down.

    6. Re:PHP is a Great Language by Oddly_Drac · · Score: 1

      "What it is is fairly well documented, but that's pretty much a requirement with an API as large and messy as PHP's."

      Next: A Diatribe on the English language. Or "why do we need more than one 'were', and what's that apostrophe shit about?"

      --
      Oddly Draconis
      Too cynical to live, too stubborn to die.
    7. Re:PHP is a Great Language by Anonymous Coward · · Score: 0

      and lets not forget is it needle/haystack or haystack needle???

      well... its
      string strstr ( string haystack, string needle)

      then how come in others like in_array its:

      bool in_array ( mixed needle, array haystack [, bool strict])

      sure backwards compatibility is great but not when it flies in the face of logic,reason and uniformity of function parameters surely!

    8. Re:PHP is a Great Language by afd8856 · · Score: 1

      I've recently started learning Python, and unfortunatly it suffers from some of the same problems (in some parts of its default library of modules). I think the fault is the C libraries that are used, when ported to the scripting language the porting authors keep the function names in the interface.

      --
      I'll do the stupid thing first and then you shy people follow...
    9. Re:PHP is a Great Language by fishermonger · · Score: 1

      That's the (only) reason I install KDE. Fire up konqueror and go to "man:/somemanpage" and get a nice html page. A little weak on the hyperlinking tough. [[Well not the only reason i install kde, interactive geometry is also cool]]

      --
      "...normal evolution would have gone Word to Frame to troff, but instead, the computer industry has gone the other way!"
    10. Re:PHP is a Great Language by TheLink · · Score: 1

      Yeah it still works in places where there's no access to the internet and someone didn't conveniently mirror the relevant portions for you.

      --
  7. Fun with analogies by doubleyewdee · · Score: 3, Funny

    The first line of this story reads 'sympleko (Mattwrites "What a beautiful world anthology is. [...]"'. Having read this I decided to put together a little one-question analogy test for my fellow readers.

    For those of you who have taken standardized tests you'll recognize the format of this analogy query:

    Acting : Kevin Costner
    Editing : _____________

    a) Pizza
    b) Chrono Trigger
    c) Slashdot
    d) None of the above.

    If you chose answer 'c' you are correct. The explanation for the answer is that in both cases the degree of quality of the first word as performed by the second is diminishing to levels almost incalculably bad.

    --


    you can take the road that takes you to the stars...
    1. Re:Fun with analogies by Anonymous Coward · · Score: 0

      except you said anthology?

  8. Why should I trust... by spyrral · · Score: 3, Interesting

    someone to review a book for me if they can't even bother to proof their own writing?

    Yes, anthology is a beautiful world, isn't it?

  9. Umm.. by deutschemonte · · Score: 3, Funny

    PHP kicks ASP.

    There, I said it.

    --
    The preceding message was based on actual events. Only the names, locations and events have been changed.
    1. Re:Umm.. by Anonymous Coward · · Score: 1, Funny

      Am I the only one who hears Peter Griffin's voice when reading that?

    2. Re:Umm.. by FlutterVertigo(gmail · · Score: 0, Troll

      Except it's not accurate.

      PHP runs under ASP.
      ASP isn't a language whereas PHP is.
      ASP is essentially an umbrella, supporting many server-side languages such as: PHP, PERLScript, JScript, VBScript, etc.
      Unfortunately, too many people seem to think:
      ASP==VBScript.
      And that's not the case at all. And it's obvious to anyone who actually knows what ASP and PHP are.
      Nice try, but no prize in the bottom of your cereal box today.

    3. Re:Umm.. by Anonymous Coward · · Score: 0

      (opens FlutterVertigo's head, flips the switch to reactivate his humor detection circuit)

    4. Re:Umm.. by nimid · · Score: 1

      Err... there's a guy called Harry Fuecks in the story and the best you could do was... PHP kicks ASP.? ;o)

      --
      A hundred and twenty characters ought to be enough for anyone...
    5. Re:Umm.. by martinsr · · Score: 1

      i guess anything kicks ASP.

    6. Re:Umm.. by Anonymous Coward · · Score: 0

      (opens FlutterVertigo's head, flips the switch to reactivate his humor detection circuit)

      Nothing happens. He is simply broken beyond repair.

    7. Re:Umm.. by deutschemonte · · Score: 1

      The Harry Fuecks thing was already done.

      I didn't want to be redundant.

      --
      The preceding message was based on actual events. Only the names, locations and events have been changed.
  10. should be !/$ by Anonymous Coward · · Score: 1, Funny

    While d!/d$ look kind of cute, it doesn't make much sense. What he wants to maximise is !/$, i.e. the ratio of bang for bucks. And this actually implies d!/d$ = 0.

  11. d!/d$ by argent · · Score: 3, Funny

    That would be the rate of change of ! with respect to $. I think simply !/$ is more appropriate.

    1. Re:d!/d$ by Anonymous Coward · · Score: 0

      Yep.

      The maximum of !/$ will be where

      a) $ = 0
      b) $ = max($) on the interval
      c) where d!/d$ = 0 aka a critical point.

      This assumes that $ is defined, continuous and differentiable on a closed non-zero interval, which I think is reasonable in this case.

      -kwy
      Why yes, I was a math major.

    2. Re:d!/d$ by proximacnt · · Score: 1

      -1 redundant Differentiable functions are continuous.

    3. Re:d!/d$ by nimblebrain · · Score: 1

      I think simply !/$ is more appropriate.

      But... you'd run into serious trouble if you got the book for free!

      ...**infinite bang**

      -- Ritchie
      --
      Binary geeks can count to 1,023 on their fingers :)
    4. Re:d!/d$ by slamb · · Score: 1
      That would be the rate of change of ! with respect to $. I think simply !/$ is more appropriate.

      Or maybe you want to minimize d!/d$, as d$ will be negative. You want the most increase of your knowledge for the least decrease of your money. Still, deltas would be more important, as these are not infinitesimal quantities. d!/d$ would only be appropriate if you are continuously charged as you read the book.

    5. Re:d!/d$ by argent · · Score: 1

      Naeh, just infinite bang for the buck. Isn't that what FOSS is all about?

  12. Yes, Slashdot crowd, is a typo!!! by armando_wall · · Score: 2, Funny

    Imagine a beowulf cluster of comments pointing the mistyped word world in the article.

    We'd get a Deep Blue!!

    1. Re:Yes, Slashdot crowd, is a typo!!! by manWorkSucks · · Score: 2, Funny

      i think you meant it is or it's :)

      --
      NERDS!!!!
    2. Re:Yes, Slashdot crowd, is a typo!!! by armando_wall · · Score: 1

      Hehe... oh, the irony!!

      Thanks, man.

    3. Re:Yes, Slashdot crowd, is a typo!!! by o0zi · · Score: 1

      Or a Deep Green - IBM's new billiards/pool playing machine, as mentioned in New Scientist today (no, seriously!).

  13. What the heck is going on? by Anonymous Coward · · Score: 3, Interesting

    I'm deeply worried by PHP becoming so increasingly popular.
    Can anyone explain this to me, please?
    What's so bad about Python, Ruby, etc.?
    I have to admit that I'm considered a Python Paladin by everyone around me, but is PHP really an alternative?

    1. Re:What the heck is going on? by Anonymous Coward · · Score: 5, Insightful

      Good question. PHP is pretty lackluster as a language, and whenever you make this assertion in public, the creator comes along and says "90 billion users can't be wrong".

      But that's actually not a bad point. PHP is *very* easy to get started with, it has a built-in template system, it has a massive library, and documentation is easy to find.

      Sure, if you are a programmer and you are getting better at programming, you will hit the walls that PHP has, but if you're just trying to get work done and you really don't care about the details, it works well.

      I use PHP quite a bit even though I can probably code in 1/4 of the time using Ruby. Because 1) I charge by the hour and 2) most clients can read and sometimes edit PHP code, but Ruby is very foreign to them.

    2. Re:What the heck is going on? by Anonymous Coward · · Score: 0

      PHP is well-integrated with Apache, and is available in most shared hosting environments.

      PHP is easy. ie., the same reason people use MySQL. Not because it's very good (because until PHP 4 it really wasn't), but because it's everywhere and it's easy to setup and use.

      PHP is fast. PHP with an accelerator is unbelievably fast. It's hard to stress this enough. You can do hundreds of dynamic pages per second on a single cheap 1U PC.

      PHP is an ideal language to develop web applications in. Session management and database handling are all parts of the original language requirements, not bolted on later. Extensions exist to wrap most C libraries for image manipulation, encryption, whatever you want. These extensions are, for the most part, fast.

      Since so many people use PHP, there is a wealth of documentation and existing code to do most whatever you need to do, including the extensive PEAR and PECL repositories.

      I wouldn't yet use it for non-web scripting (that's why God invented Perl), but for most web stuff it really can't be beat.

    3. Re:What the heck is going on? by Anonymous Coward · · Score: 0

      Face it, your the kind of person who is deeply worried about anyone thinking in a different way than you. PHP is not for you. Please stay away.

      There is nothing bad about Python, Ruby, etc. they are great languages. They appeal to people like you who have strong opinions about the way people should program because they were designed by people with the same opinion.

      PHP just doesn't have the dogma of the OO languages, nor the anarchy of Perl. You may be shocked (please sit down before continuing) but there are programmers out there, lots of them, who don't create a UML diagram before they slap an email form or guestbook on a website.

      You can build N-Tier in PHP or not. MVC or not. Use formal patterns or not. Templates or not. OO or procedural. Handle errors with return codes, callbacks or exceptions. There are tons of libraries and code available for solving problems.

      The bottom line is that PHP is one of the most effective tools for building web apps, but it makes a very poor religion. Hence your consternation Mr. Paladin. Stick with Python.

    4. Re:What the heck is going on? by bretharder · · Score: 1

      Whats so bad about PHP?

    5. Re:What the heck is going on? by Mr.+Slippery · · Score: 5, Insightful
      I'm deeply worried by PHP becoming so increasingly popular. Can anyone explain this to me, please?

      What's to explain? It gets the job done. It's a tool designed specifically for the job of making websites, unlike Perl or Python. It's easy for beginners to pick up, yet featured enough to not drive experienced coders nuts. It's popular enough that you can find people to pick up existing projects, and that there'll still be support for it in 10 years.

      What's so bad about Python, Ruby, etc.?

      Aside from the horror of syntactically significant whitespace? :-) And that they are general pupurpose languages not designed specifically for the web? To some degree, it's a matter of momentum - if you code a project in Python, you'll have trouble finding someone to take it over when you leave/get promoted/get run over by a bus. You won't have that problem with PHP.

      --
      Tom Swiss | the infamous tms | my blog
      You cannot wash away blood with blood
    6. Re:What the heck is going on? by Thott · · Score: 5, Insightful

      It's all about security.

      When I ran an ISP, there was no way I'd let users use mod_perl, because mod_perl scripts run with the same rights as the webserver. This means that one user could write a script that read the data of another user. Bad.

      PHP has a built in security hack to work around this. All the file manipulation functions check the owner of the target file, and make sure it's the same as the owner of the PHP script. It's a simple hack, but that's why PHP is popular. ISP's will allow people to run PHP scripts that are fast, i.e. part of the apache process. They won't allow the same for perl, python, ruby, or anything else.

      Want perl to be on top again for web work? Take mod_perl, fork it, and add that security hack. For total dominance go one step further and have it automatically put useful CGI environment data into global variables (%CGI for GET/POST, %APACHE for apache data, %COOKIES for cookies). Think up an extension for this new type of perl script, perhaps even two of them, one that runs the script directly, and the other that expects HTML with script breakout tags (".fps" for "fast perl script" and ".fph" for "fast perl hypertext" - whatever).

      Then you'd have something that's fast, sexy and makes ISP's happy. It's a guaranteed hit.

      --Thott

    7. Re:What the heck is going on? by chcorey · · Score: 1

      Besides what the others have said about PHP, I particularly found that making dynamic images was a big plus for me. Using GD and truetype add ons was incredibly easy.

      I love being able to make dynamic thumbnails with less than 10 lines of code.
      I also found it useful for generating maps. You store the plot points in the database and generate the map and the legend on the fly. Useful for real estate/oil well/garage sale applications, to name just a few.

      I'm sure you probably can do this kind of stuff with other languages but PHP makes it dead easy.

      Want to have it so the user can select the quality of images they see on the webpage based on their connection? You can do it with one line!!! (well changing the image quality that is).
      Also neat is that you can take a huge image (like a map) and chop it into 8.5 x 11 chunks so that it prints well on all printers.

      The great thing is, I was able to teach myself this stuff by just looking at the manual.

      Ok ok I'll stop parading this language around, but I definately think there is a place for PHP and think you should give it a fair chance. Now if only I could have the desire to learn ASP (so many job postings are asking for it as a skill).

      --
      Dog for sale: eats anything and is fond of children
    8. Re:What the heck is going on? by afd8856 · · Score: 2, Interesting

      I've recently switched from PHP to Python when programming for the web. I've realized that my skills in PHP would not help me for anything else than webprogramming. I'm glad I did this, 'cause, for example, I've just finished a contract for creating a windows (office stuff) app with Python.

      Also, whitespace is not so bad in Python, it's just different. If you really need to see brackets, you can simply add #{ and #} where you would want them to be.

      The real problem with Python for the web is that there is not a "definitive" framework for programming for Apache. There is mod_python with PSP, spyce, webware, skunkweb, quixote, cherrypie, etc. When I've started learning Python, I've wanted to build a simple weblog application, and it was hard for me, because I had to learn the framework at the same time as learning Python. (Also, I didn't had enough time to dedicate to this task.)

      But then something happened :). I've discovered Plone and Zope. What would have previously taken me months or weeks of work, I can make in hours and at most days. (None of the PHP CMS' at the time were as developed and customizable as Plone - have a laugh comparing PHP-Nuke, PostNuke or Tiki to Plone. I didn't know about Drupal or other more advanced PHP CMS then)

      PHP has another aspect really good aspect that makes it a killer language: good documentation. The users can add comments to the web version, there is a sweet CHM help file packed with the web version (with comments) and those comments often have examples or useful snipets or best practices. I wish Python had that...

      --
      I'll do the stupid thing first and then you shy people follow...
    9. Re:What the heck is going on? by bckrispi · · Score: 1
      PHP has a built in security hack to work around this. All the file manipulation functions check the owner of the target file, and make sure it's the same as the owner of the PHP script.

      Where is this feature documented? I've been groking the PHP manual and haven't found it...

      --
      Xenon, where's my money? -Borno
    10. Re:What the heck is going on? by Thott · · Score: 1
      It's called safe mode, documented here.

      --Thott

  14. A word if I may: by Anonymous Coward · · Score: 5, Funny

    Gentlemen, the time has come for a serious discussion on whether or
    not to continue using Perl for serious programming projects. As I will
    explain, I feel that Perl needs to be retired, much the same way that
    Fortran, Cobol and Java have been. Furthermore, allow me to be so bold
    as to suggest a superior replacement to this outdated language.

    To give you a little background on this subject, I was recently asked
    to develop a client/server project on a Unix platform for a Fortune
    500 company. While I've never coded in Perl before I have coded in PHP for
    fifteen years, and in Javascript for more than twenty, I was stunned to see how
    poorly Perl fared compared to these two, more low-level languages.

    Perl's biggest difficulty, as we all know, is the fact that it is by far
    one of the slowest languages in existance, especially when compared to
    more modern languages such as Basic and HTML. Although the reasons for
    this are varied, the main reasons seems to be the way Perl requires a
    programmer to laboriously work with chunks of symbols globbed together
    senslessly.

    Requiring a programmer to manipulate unreadable is a tedious way
    to program. This was satisfactory back in the early days of coding,
    but then again, so were punchcards. By using what are called
    "scalars" a Perl programmer is basically requiring the computer to do
    three sets of work rather than one. The first time requires the
    computer to use a dollar sign to indicate "dollar value" of the scalar. The
    second time requires it to perform the needed
    operation on this value. Finally the computer must delete the
    duplicate set and set the values of the original accordingly.

    Clearly this is a horrendous use of resources and the chief reason why
    Perl is so slow. When one looks at a more modern (and a more serious)
    programming language like HTML, Javascript or - even better - PHP
    that lacks such archaic coding styles, one will also note a serious
    speed increase over Perl.

    So what does this mean for the programming community? I think clearly
    that Perl needs to be abandonded. There are two candidates that would be
    a suitable replacement for it. Those are HTML and PHP.

    Having programmed in both for many years, I believe that PHP has the
    edge. Not only is it several times faster than Perl its also much easier to
    code in. I found Perl to be confusing, frightening and intimidating with
    its non-GUI-based coding style. Furthermore, I like to see the source
    code of the projects I work with. HTML's source seems to be under the
    monopolistic thumb of W3C much the way that Perl is obscured from us by
    the marketing people at the FSF. The GPL "shared source" under
    which PHP is released definately seems to be the most fair
    and reasonable of all the licenses in existance, with none of the
    harsh restrictions of the BSD license. It also lacks the GPLs
    requirement that anything coded with its tools becomes property of the
    FSF.

    I hope to see a switch from Perl to PHP very soon. I've already spoken
    with various luminaries in the Perl coding world and most are eager to
    begin to transition. Having just gotten off the phone with Mr. Alan
    Cox, I can say that he is quite thrilled with the speed increases that
    will occur when the Linux kernel is completely rewritten in PHP. Richard
    Stallman plans to support this, and hopes that the
    great Swede himself, Linux Torvaldis, won't object to renaming Linux
    to Gnu/PHP/Linux. Although not a PHP coder himself, I'm told that Slashdot's
    very own Admiral Taco will support this on his web site. Finally,
    Dennis Ritchie is excited about the switch!

    Thank you for your time. Happy coding.

    1. Re:A word if I may: by The_reformant · · Score: 2, Funny

      HTML is a great language, if they made a openGL library for it I wouldnt ever bother with C++

      --
      I have discovered a truly remarkable sig which this post is too small to contain.
    2. Re:A word if I may: by MavEtJu · · Score: 2, Funny

      You forgot the "netcraft confirms" and the comments of the people leaving the perl-project.

      --
      bash$ :(){ :|:&};:
    3. Re:A word if I may: by herrvinny · · Score: 1

      Mod Up Funny!

      This is bloody hilarious. Mods, whoever voted the parent Troll is frankly incompetent. For the non-programmers out there: PHP is a hypertext preprocessor. It's entirely focused on creating dynamic web pages. Perl, on the other hand, can do far more than just CGI scripts for web servers. It's a useful language for automating things in UNIX, among other things.

    4. Re:A word if I may: by Unordained · · Score: 1

      ... and I have never, ever used PHP's ability to embed PHP code inside of HTML. I'm a C coder at heart, so I still use 'echo' and whatnot for those few cases where there's actual output; most of my code however is algorithm-oriented, with a little bit of output here and there ... because of this, I have trouble seeing PHP as anything but yet another interpreted language like perl, except with slightly different syntax and different built-in functionality and libraries. and I have used PHP as glue between programs, particularly between my own C++ programs and existing utilities provided alongside the OS ...

      What a language is good for is determined by a few things:
      a) what it can express (access to libraries, etc.)
      b) what it can express quickly

      PHP has access to libraries for doing all sorts of random work, just like perl or C. And the speed with which it can express a given task varies at least partially (mostly?) based on your familiarity with the language. I've coded in PHP more than perl -- it's been months since I've touched perl, so I likely don't want to spend half an hour re-learning parts of it when I need a script written. I coded in C++ just a few minutes ago (and most of every day), so I may still prefer that to PHP even for some small script-like tasks, unless I just know I don't want to deal with input/output stuff, formatting, etc. How "good" a language is (in general) is rarely a factor, nor is "what the language was meant for" -- things change, evolve ... eh.

    5. Re:A word if I may: by JabberWokky · · Score: 2, Insightful
      I assume you are trying to continue the humor of the grandparent post. That or you are either a troll or simply ignorant of PHP.

      Lest anybody, not knowing any better, believes you, I'll point out that PHP has been more than a hypertext preprocessor for years and there is a growing set of CLI tools written in it as well as a few GUI libraries. stdin, stdout, ncurses support and plenty of other non-web related tools exist that are part of the core package. These are available when compiled as an interpreter rather than the usage you seem to be familiar with as an Apache (or other web server) module.

      --
      Evan

      --
      "$30 for the One True Ring. $10 each additional ring!" -- JRR "Bob" Tolkien
    6. Re:A word if I may: by FuzzyBad-Mofo · · Score: 1

      $ which php
      /usr/bin/php

      Not *just* a hypertext preprocessor, thank you very much.

    7. Re:A word if I may: by Anonymous Coward · · Score: 0

      "While I've never coded in Perl before I have coded in PHP for fifteen years"

      That's pretty impressive considering PHP/FI was created by Rasmus Lerdorf in 1995.

  15. wow by ArgyleAgent · · Score: 1

    I just finished teh first 3 chapters yesterday, boy howdy do I have my finger on the pulse of news for nerds!

  16. Sample Chapters by kubed · · Score: 5, Informative

    Here are the URL's for samples of the first 4 chapters (so you don't have to give your e-mail address to SitePoint).

    ZIP format:

    http://www.sitepoint.com/books/phpant1/phpant1-sam ple.zip

    StuffIT format:

    http://www.sitepoint.com/books/phpant1/phpant1-sam ple.sit

    tar/gzip format:

    http://www.sitepoint.com/books/phpant1/phpant1-sam ple.tgz

  17. mod parent -1, pedantic by Anonymous Coward · · Score: 0

    as well as grandparent and grandparent's next older sibling

  18. His excuse by scheme · · Score: 2, Funny
    While d!/d$ look kind of cute, it doesn't make much sense. What he wants to maximise is !/$, i.e. the ratio of bang for bucks. And this actually implies d!/d$ = 0.

    The author of the review is a mathematics preceptor at Harvard, you don't actually expect him to understand calculus do you? This way when those Harvard undergrads come to him for help in math, he can give them totally wrong information and truthfully say he did his best to help them.

    --
    "When you sit with a nice girl for two hours, it seems like two minutes. When you sit on a hot stove for two minutes, it
  19. Growth of productivity function vs. time by Anonymous Coward · · Score: 0

    After all, complexity theory tells us that constant factors and offsets are irrelevant - so shouldn't you be choosing the language that'll make you most productive after, say, 5 years of learning it?

    1. Re:Growth of productivity function vs. time by random_static · · Score: 2, Insightful
      After all, complexity theory tells us that constant factors and offsets are irrelevant - so shouldn't you be choosing the language that'll make you most productive after, say, 5 years of learning it?

      that would have us all coding in Common Lisp, wouldn't it?

  20. Just a thought... by Wild+Bill+TX · · Score: 1

    Why is the review of Volume I presented here? That seems like really bad targeting, as I would guess that the vast majority of Slashdot (News for Nerds) readers interested in a book on PHP already know the basic syntax.

    Pardon me if I've missed something.

  21. maximal code reuse, consider object orientation by __aanonl8035 · · Score: 2, Interesting

    I have heard this statement so many times but never have I seen proof that OOP actually leads to code reuse and/or more maintainable code. I know I can only add anecdotal evidence with my comment, but I have never encountered a project where OOP has led to any significant savings in time or reuse. I think where the idea that OOP leads to a better project is corollary.

    No one starts off thinking in OOP. They learn it through books or college (etc...) and it is that process of thinking about your program before actually diving in and coding that leads to a "better program"

    1. Re:maximal code reuse, consider object orientation by Anonymous Coward · · Score: 0

      Well, I agree with what you are saying generally, but I disagree about OOP and code reuse.

      The code reuse of objects comes *within each project* due to refactoring and simplifying.

      And OOP facilitiates this because of encapsulation: you can test and improve each part of your program in isolation, and the whole thing still works.

      Whenever I take 2 or 3 classes that do similar things and then merge them into one class, it's a very powerful feeling, and often gives me greater insight into the program.

    2. Re:maximal code reuse, consider object orientation by mios · · Score: 1

      Hah .. that's almost really funny. Let's forgo the philosophical inquiry as to how people think and perceive their natural world (cuz I believe people may actually think in terms of OOP) I don't see how you can argue you code reuse does not happen in oop coding to the interface, not the implementation .. ever throw around "some type of List" and use it as an ArrayList, or LinkedList or whatever the heck type of collection it is and just iterate/trafverse through it transparently and w/o worry? I bet you have, and if you haven't, well then ... there it is. Does that count for re-use?

    3. Re:maximal code reuse, consider object orientation by PhrostyMcByte · · Score: 3, Interesting

      try programming a game.

      class "monster" can inherit from class object.

      object has standard data that pertains to every object in the world, like positioning and physics stuff.

      object has a virtual method tick(), so any class that overrides it can process data specific to it. later you can loop through an object pointer array that holds all the objects in your scene and call tick() and render() for each one.

      yes, OOP is useful. not required, but definately useful.

    4. Re:maximal code reuse, consider object orientation by Jimmy_B · · Score: 1

      In theory that's great, and it's certainly a big improvement over giant switch statements, but in reality object orientation is only marginally better than using hand-made function tables. The biggest drawback is scripting; usually, the details of specific monsters are written in a different (specialized scripting) language, and getting the OO systems of two different languages to play nice with eachother is just about impossible. While very nice for small- to medium projects, ironically, it doesn't scale like it should, and classes tend to end up as nothing more than glorified namespaces.

  22. what a world! by theridersofrohan · · Score: 2, Interesting
    "What a beautiful world anthology is. It comes from the Greek for a gathering of flowers".


    Err no. anthology is not a "world", at it comes from the Greek for word/speech about flowers (logos=word/speech, anthos=flower).

    1. Re:what a world! by Metaplasmus · · Score: 2, Informative

      ...it comes from the Greek for word/speech about flowers (logos=word/speech, anthos=flower). Well, sort of. The word logos can indeed mean a word or a speech, but it has other meanings too--calculation and reckoning, for example. It comes from the verb lego, whose core meaning is "to gather/pick up," out of which come the senses of counting something and then speaking of it (the last being the most common sense of the word in ancient Greek). So despite appearances, an anthology is, indeed, a gathering of flowers.

  23. More in the series by FraggedSquid · · Score: 3, Funny

    The PHP Anthology - Volume 3 'Return of the Ping'

    --
    You don't need a lab to make mud.
    1. Re:More in the series by quenda · · Score: 1

      > The PHP Anthology - Volume 3 'Return of the Ping'

      Thats Volume 3 "Second Foundations", you illiterate clod.

      (Asimov's great vision, until some spoilsport mathematician invented Chaos Theory, which rather killed the idea of Psychohistory. )

  24. Someone have to say it... by Psionicist · · Score: 0

    Harry... Fucks?

  25. Please remember by timothv · · Score: 1

    that PHP Sucks! Have a nice day!

  26. What a beautiful world word is... by Anonymous Coward · · Score: 0

    its two bad they speeled in wnrog.

  27. Broken link by asciono · · Score: 1

    Maybe I'm just tired, but to find PEAR::HTML_Table you should try this link instead. ;)

  28. Comparison? by memco · · Score: 1

    How does this compare with other PHP books? To respond to an earlier post, I am perhaps in the minority of /. nerds who don't know PHP nor have significant coding experience to just pick it up. Can anyone recommend a better book than the current subject?

    --
    Get me a meat pie floater!
    1. Re:Comparison? by FuzzyBad-Mofo · · Score: 2, Informative

      I haven't yet read the subject of this book review, but I did find O'Reilly's Programming PHP to be a useful and comprehensive overview of the language. Of course, it was published in 2002, so today I would recommend going with something a little newer. But really, the documentation on http://php.net is excellent -- I'd check that out before spending money on dead tree.

  29. it's.... by Anonymous Coward · · Score: 0

    thare. I announced it a few weeks ago, to help with all the bad enlisheisms. No more being rong with spelung arrers. Tee aitch aaa are eee thare. Fits in all situations and with all contexts, and no need to try and rememberise diffrent spelungs that aren't not nesseceesauary..

  30. The next volume... by Chris+Mattern · · Score: 2, Funny

    ...will be about how to use PHP in a Microsoft environment. It will be titled "Foundations and Empire".

    Chris Mattern

  31. you don't say by Anonymous Coward · · Score: 0
    Harry Fuecks

    He's not the only one who does ... well, maybe on Slashdot he is.

  32. Anthology, Boquet == Nosegay by PGillingwater · · Score: 1

    What a beautiful world anthology is. It comes from the Greek for a gathering of flowers, and in literature means a collection of works. Harry Fuecks, a very frequent contributor to the SitePoint community PHP forums, has gathered a bouquet of PHP best practices in a new book.

    I'm somehow grateful you didn't use the word nosegay.

    --
    Paul Gillingwater
    MBA, CISSP, CISM
  33. PHP is the COBOL of new century! by Cyberax · · Score: 0, Troll

    When will PHP die and will be replaced by something more elegant and useful?

    Honestly, PHP is just like BASIC for WEB. Object oriented programming in PHP is still a pain, there's no clear notion of something like packages, language itself is a mess, no standard intermediate 'bytecode', etc.

    Why would anyone want to use such a clumsy tool when things like Tapestry, Echo, Struts exist?

    No, this is not a troll. I'm just sick of news about PHP.

  34. UML on the rise by brlewis · · Score: 1

    There are more and more inexpensive services using User-Mode Linux, so security hacks like the one you propose are getting less and less important.

    1. Re:UML on the rise by Cybrr · · Score: 1

      It's still unprofessional to have your site go down.

      --
      Why did GEAR crush RDP?
  35. CPAN by TheLink · · Score: 1

    That's what I call code reuse. :)

    --
  36. Re:Umm.. (Nit-Picker Warning) by metacosm · · Score: 1

    ASP is an interface to langauges, not a langauge in and of itself.

    In theory you could do ASP pages in PHP, if the langague was setup properly. You can already do ASP in Perl, Python, JScript and VBScript, as well as other langauges I am sure I am forgetting.

    Just tired of people comparing ASP as a langauge to PHP, very annoying.

    P.S. I am aware that when people say "ASP" they are most likely referencing ASP when used with VBScript -- so don't bother reminding me. :)

    P.P.S Told you it was a nit-picky post :)