Slashdot Mirror


Learning PHP 5

John Suda writes "There are more new books being published about PHP than you can shake a joystick at. PHP (along with program friends - MySQL and Apache) has become very popular among developers and web designers, and for good reason. As a programming language, it is particularly suited to web development projects, while being relatively easy to write, use and learn. More importantly, it's open-source and free, cross-platform, and widely supported. David Sklar's Learning PHP5 is one of the latest volumes dealing with PHP. It describes itself as 'a Pain-Free Introduction to Building Interactive Web Sites,' and provides a gentle introduction to the latest version of PHP, which is version 5 and only recently available." Read on for Suda's review. Learning PHP 5 author David Sklar pages 432 publisher O'Reilly rating 9 reviewer John Suda ISBN 0596005601 summary An accessible introduction to the popular web scripting language PHP

This book is not particularly useful for those experienced already with PHP, nor for those wanting to upgrade their knowledge of PHP from versions 4 and earlier to the newest version. It's also probably not particularly useful for those power programmers who need and want a deep and comprehensive coverage of the topic. But it is a very well-written and designed introduction to PHP 5 for beginning programmers or those experienced PERL, ASP, or Cold Fusion programmers who want to learn a different language. There are many illustrations and code samples sprinkled throughout the book. Sklar, however, skims over some topics, concentrating instead on practical examples.

The publisher is O'Reilly Media, Inc. which seems to have an editor's policy of covering complex computer-related topics in a comprehensive manner by publishing a range of volumes covering different aspects of a topic or from different angles or for different audiences. O'Reilly also publishes volumes on moving to PHP 5 (Upgrading to PHP 5), detailed and technical PHP (Programming PHP), and a collection of solutions to common PHP programming problems (The PHP Cookbook).

Sklar is an experienced consultant in computer software development and technical training. He is the author of Essential PHP Tools and coauthor of the aforementioned The PHP Cookbook. He takes a deliberate and comprehensive approach to explaining PHP 5, not in great depth, but with the intent of providing enough information, concepts, detail, and scope to create a pleasant and useful read of a technical subject. The basic promise of PHP is in the relatively easy creation of more dynamic and interesting web sites which would include, for example, product catalogs, blogs, photo galleries, event calendars, forms, and more.

There are 13 chapters and 3 appendices. The early chapters provide an orientation to PHP, including its place in contemporary web development, its basic rules, and its syntax. They explain the basic background of PHP and how it interacts with the browser and web server. Later chapters introduce primary concepts like loops, arrays, and functions. The idea here is to facilitate learning the fundamentals of the grammar and vocabulary. Chapters 2 through 12 have short exercises at the end of each to allow the reader to practice writing PHP code and to test learning. (The answers are contained in Appendix C.) Experienced programmers and geeks may recoil at the inclusion of these exercises, but they are useful for beginners.

Chapter 6 provides a practical exercise - how to make and use a web form. The author shows how to access form variables, how to validate user-inputted data for security and efficiency reasons, and how to process forms using functions. Chapter 7 shows how PHP interacts with database programs, like SQL and Oracle, but focuses primarily on MySQL, and demonstrates how to organize data, connect to a server-based database, create tables, and enter and retrieve data.

The rest of the middle chapters cover the use and implementation of cookies and sessions, handling dates and time, and working with files. The practical exercise using dates and times is creating and displaying a monthly calendar. The final chapters provide brief but practical coverage of XML, debugging, and in Chapter 13, other PHP aspects. PHP is amazingly useful, flexible, and practical. One can deal with graphics, PDF documents, and other media like Flash and Shockwave. It also has mailing and file uploading functions, encryption capabilities, and (for more experienced coders) the ability to run shell commands. The upgraded PHP 5 has new capabilities, which now include object-oriented programming.

Appendix A covers installing and configuring PHP for Windows, Mac OS X, and Linux; Appendix B is a short primer on regular expressions and how to use them with PHP.

I found the book to be the most accessible introduction to PHP I have read. It provides the basic fundamentals, engages the reader in practical examples, reinforces learning with exercises, and provides an overall perspective on the scope of PHP programming.

You can purchase Learning PHP 5 from bn.com. (Code examples used in the book can be downloaded at the O'Reilly site for the book, linked above.) Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

10 of 201 comments (clear)

  1. I have a bit of a bone to pick. by gthumb · · Score: 5, Interesting

    See, this is a book review of a PHP tutorial book. This is not an excuse for the legions of Perl bigots to run out here and start bashing PHP based on outdated versions and foolish generalisations. You say that PHP isn't ready for enterprise-ready applications, but this is a pretty transparent falsehood. There's nothing inherent in a proper installation of mod_php to prevent a site the size of Slashdot or Google from running with PHP instead of Perl or, G-d forbid, ASP.

    You say that PHP's "OOP model" "sucks". First off, the term "OOP model" is frankly idiotic. OOP isn't enough of a coherent programming paradigm to be considered a single "model" or "base". Further, only PHP 4 has inferior OOP features. Why? Simply because they weren't in demand. Most people don't need OOP. It's overengineering overkill for the vast majority of applications.

    It's also been alleged that PHP is somehow slower than Perl or Python for Web. However, Perl and Python all have to be compiled before execution, much the same as PHP. It's well known that PHP compilers and cachers already exist, so there's no reason why running the smallest PHP script shouldn't take any more than perhaps a 1/400 of a second. That's a pretty reasonable time, no?

    PHP is maturing. Its version number is the same as Perl; it's more popular than Perl; it's almost as mature as Perl. It has more users than Perl, more bug fixes being put out, and its few idiosyncrasies are very well known. Frankly, there's fewer traps for a beginning PHP user than a beginning Perl user.

  2. What does it do differently? by colin_n · · Score: 4, Interesting

    PHP4 is to PHP5 as ASP is to ASP.NET? Is that statement correct? What advances does PHP5 make that puts it in direct competition with ASP.NET?

    --

    --------- I have no signature
  3. PHP vs Zope, Pearl vs Python by dargaud · · Score: 4, Interesting
    I had to use Perl for a project some time back. It was quick and dirty and did the job. At the same time I learned python without managing to apply it to the project. I recognized that I liked python better, but perl was faster to implement.

    Slightly later I did a web project where some interaction was necessary. Instead of my old cgi-scripts or DHTML, I started it in PHP and Zope, as a newbie in both. While recognizing that Zope seems very clean I was totally unable to wrap my head around its basic concepts ('TAL' anyone ?). In one afternoon I had PHP installed and a 140 pages of PHP converted from HTML, up and running. Going from HTML to basic PHP takes about 5 minutes.

    So, while I regret to say that, some languages look cool but others just do the job. PHP is certainly one of the latter.

    --
    Non-Linux Penguins ?
  4. In fairness to the python community by jbellis · · Score: 3, Interesting

    there are more options for python on the web than Zope, which even many pythonistas consider overengineered and even un-pythonic in many ways.

    WebWare and Quixote are probably the biggest; another called SnakeSkin was just announced as having reached 1.0 today.

  5. Re:PHP or Perl? by Flaming_cows · · Score: 2, Interesting

    Er, PHP stands for 'PHP: Hypertext Preproccessor' (gogo recursive acronyms!), not Personal Home Page.

  6. Re:PHP or Perl? by phek · · Score: 3, Interesting

    Neither is really better than the other, it's really just a preference. Saying that php is a simpler version of Perl is totally wrong. The two languages are nearly as different as can be while still striving for the same goal (ok maybe not THAT different but they are very different). The style differences between the two happen to remind me of the differences between basic and pascal if you're familiar with either of those.

    Some of the reasons I prefer PHP over perl is because it's a lot more similar to C than perl is. Plus, if I remember right with perl, you have to enable execgi in apache for any directory you want to run perl scripts in (something that i'd be very against doing). But probally the main reason me and lots of other people who prefer PHP hate perl is CPAN. CPAN is the perl libraries which you always end up having to update and it can sometimes be a big pain in the ass. The only thing perl has that php doesn't have (that I know of at least) is signal handling, so you can have the code do something if the program receives an INT signal, or any other signal (something you probally wont ever use).

    In my own experience, I learned perl just before I discovered php. Neither language was really hard (I had other experience with non web based languages already), but when learning perl something just felt wrong about the style, awkward as another poster put it.

    So in conclusion... don't do any web programming whatsoever, it sucks and you'll wish you never did. Theres nothing worse than having some asshole who doesn't know anything about computers come up to you and say "The font seems a little strange". Come on... WTF DOES THAT MEAN?!? So then you go and make their website Teal, Orange and Pink because fuck them, and then they come back complaining about the color now, but the font looks good. I still do use PHP though I just try to not do any web programming with it. Both PHP and Perl are great for some simple programs that are just a little too much for a scripting language like bash.

  7. Re:open-source vs. suitability to task by Just+Some+Guy · · Score: 3, Interesting
    So, being open-source is more important than suitability to task?

    For many of us, being Free Software is "suitability to task". That is, non-Free software is an automatic disqualification from the running.

    I've built my company's web apps on Zope, Python, PostgreSQL, and FreeBSD. None of those "vendors" will go out of business next year (but if they did, who cares?). There will be no forced upgrade to a more expensive version that we don't need. We can get timely (and free) security updates and feature upgrades. We have an infinite-user license.

    How on Earth could a closed vendor compete with that? The answer: they can't. There are far too many Free options for developing network applications to even glance at the proprietary stuff.

    Oh, and my boss likes our system so much that he just gave me permission to release all of the non-business-logic software I've written over the last year under an open source license. The only remaining step is to pick the license that we'll use to share our work with the community that made it all possible. Have I mentioned today that I dig my job?

    --
    Dewey, what part of this looks like authorities should be involved?
  8. Re:PHP - poor design by LordLucless · · Score: 2, Interesting

    But to the point - PHP. When I am forced to use PHP for something, I am constantly amazed at the poor design and horrific bloat of the language. Case in point - there are no less than eleven different sort routines.

    The number of sorting routines isn't necessarily bad - they're all well documented, and all have differences. I don't think having multiple sort routines slows the language down at all, so I don't see the problem.

    One might think that having all these different routines might make it easier to perform a custom sort. Nothing further from the truth

    That is more of a problem, I think. If coding a customize sort is more difficult in PHP than in an other language, then that's bad. I can't really see how that would be though - implementing a custom sort algorithm doesn't depend hugely on the features of a language - its all basic loops and conditions.

    I code in PHP and ASP.NET. I much prefer ASP.NET - things are much neater, better organized, and there is a clear division between form and content. But you don't need ASP.NET for most sites, and most sites I've done didn't. They needed something quick, simple and fairly lightweight. And PHP worked fine there. PHP is easy to use - if you aren't doing anything particularly hard. It's exceptionally easy to do easy stuff, and hard to do the hard stuff with PHP. So use it for the easy stuff, and use ASP.NET for the easy stuff. Problem solved.

    --
    Just because you're paranoid doesn't mean there isn't an invisible demon about to eat your face
  9. Re:PHP - poor design by Jerf · · Score: 2, Interesting
    If coding a customize sort is more difficult in PHP than in an other language, then that's bad. I can't really see how that would be though - implementing a custom sort algorithm doesn't depend hugely on the features of a language - its all basic loops and conditions.

    That is almost certainly not what the OP meant. Staying language generic, suppose you have an array of two-element arrays:

    [[1, 3], [2, 2], [3, 1]]

    and you want to sort this array by the second element. In Perl, that's
    use Data::Dumper;
    my @array = ([1, 3], [2, 2], [3, 1]);
    my @sorted = sort { $a->[1] <=> $b->[1] } @array;
    print Dumper(@sorted);
    and viola, an array sorted with a custom compare function. In Python,
    array = [[1, 3], [2, 2], [3, 1]]
    array.sort(lambda a, b: cmp(a[1], b[1]))
    print array
    And I can do this in Javascript, C ("man qsort"), C++'s STL (in the verbose way the C++ does things, but still), and at a bare minimum pretty much any language where functions are first-class objects, which with the possible exception of C/C++ I now consider an absolute requirement for any language I will use.

    A language that makes this hard isn't worth using; it's a "smell". Your not knowing this, no particular offense intended, rather re-inforces the original poster's point: The only people singing the praises of PHP are those who aren't terribly experienced with other languages, and it tends to show pretty clearly. (No, ASP.NET is not sufficiently different. Same domain, same basic approach, slight difference in evolution.) As penance, I order you to spend a month with OCaml, for your own good.
  10. I just had a week of training with the author... by djcatnip · · Score: 2, Interesting

    ... At Big Nerd Ranch, and it was awesome. If you like the book and you want more personal training, they're talking about doing this PHP5 bootcamp again in about 5 months. It's held at a fantastic retreat setting in georgia, so it's fairly free from distraction. If you've tried to find PHP training, you know this is an unserviced market largely, so if/when they offer this class again, jump on it fast.

    I've been about 3 years into self-taught programming with books, open source examples, and trial and lots of errors up until a couple of weeks ago. Now I've got a pretty good grasp on the mechanics of object oriented programming in PHP5, Pear, and the new XML stuff. David Sklar does a great job at teaching the concepts and practical implementation of the concepts.

    I was fortunate enough to be able to migrate my customer facing server to php5 a couple of days ago, so I'm able to benefit from all the new stuff I learned just over a week ago. It's been very cool.

    --
    I make these: http://beatseqr.com