Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
PHP Books Media Programming Book Reviews

Spring Into PHP 5 229

Michael J. Ross writes "A professional programmer could at any time be tasked with developing a nontrivial application using a language or Web technology with which he or she is unfamiliar. A common response is to quickly scan code snippets in Internet newsgroups and online tutorials, copy and paste code that looks applicable to the task at hand, and then lose valuable time trying to make it all work and control what was created -- not unlike Dr. Frankenstein's experience. A smarter approach is to learn the language basics in sequence as rapidly as possible, not getting bogged down in excessive sample code. For developers seeking to learn PHP using the latter approach, Steven Holzner's Spring Into PHP 5, published by Addison-Wesley, would be an excellent choice." Read on for the rest of Ross's review.
Spring Into PHP 5
author Steven Holzner
pages 340
publisher Addison-Wesley
rating 8
reviewer Michael J. Ross
ISBN 0131498622
summary A comprehensive and no-nonsense primer on the basics of PHP.


This title is another entry in Addison-Wesley's promising "Spring Into" series, which, as suggested by the name, is aimed at developers who want to jump into a new technology and get up to speed as quickly as possible, but without missing any of the essentials. In the case of Holzner's PHP book, this goal is pursued by presenting the information in so-called "chunks," with each spanning just a few pages. Every chunk attempts to cover only one or a few related ideas, and is designed to build upon earlier chunks. The bulk of the explanation takes the form of code samples, which fortunately are short enough in length and clear enough in composition to be easily digestible. This is in stark contrast to far too many other programming books on the market, whose code samples can span multiple pages, making it difficult for the reader to discern all of the ideas that the author is trying to get across -- especially when the reader has to flip back and forth between pages. Even worse is how some authors (such as Deitel and Deitel) use lengthy code listings -- sometimes even complete applications -- to demonstrate many ideas at once, which can be quite confusing, especially for the newbie reading about a challenging language for the first time. As Holzner notes in his preface, his book is example-oriented, with dozens of tested code samples. But none are overwhelming.

Spring Into PHP 5 was published on 12 April 2005. It is organized into nine chapters, covering a range of topics: PHP essentials; operators and flow control; strings and arrays; functions; PHP in HTML pages; Web forms and input validation; object-oriented programming and file handling; PHP and databases; cookies, user sessions, FTP, e-mail, and hit counters. The book has two appendices. The first one, on PHP language elements, is remarkably complete, considering that it only fills 18 pages. Owners of the book will likely find themselves turning to this material quite frequently. The second appendix lists the most commonly used functions in PHP, particularly those dealing with arrays, strings, and files. These two appendices combined go a long way to making this book more than an approachable primer -- it could serve as a reference book for the language for any reader not required to dig into the more obscure intricacies of PHP. Readers with those needs will have to use more detailed sources, such as the online PHP Manual.

Each one of Holzner's chapters explains the core concepts, using the bite-sized chunks mentioned earlier. This approach is somewhat similar to the "recipes" found in many books published by O'Reilly Media, and it works well here for introducing a computer language. Holzner's writing style is clear yet never condescending, and concise yet never cryptic. The intended reader only really needs an understanding of simple HTML and how to edit text files, to make this book worthwhile and usable. The book is meaty with information, and yet not too lengthy. This is a refreshing change of pace from countless other computer language books that are bloated with redundant sample code and overly wide margins, apparently in an attempt to entice the consumer with maximum page count per dollar.

Some programming books try to move the novice along at too rapid a pace, which can get quite discouraging if and when the reader is unable to follow the discussion, and particularly if trying to follow the author in building a working example. But a far more common mistake among programming books, is to drag out the process with humongous code listings or redundant verbiage (such as following the senseless rule of telling the reader something three times -- a technique that makes far more sense for speechwriting). Holzner sets and maintains an excellent pace, partly by keeping the code snippets reasonably sized, and partly through his modular approach of presenting ideas in chunks.

The physical book itself is well made and attractive, with a readable font face and size, and intelligent use of bolding to highlight those lines of code upon which the reader should focus. My only complaint in terms of the presentation, is that the gray background used for the code samples could be lightened up a bit, to make the text itself stand out more, especially the bold text. All of the screenshots are in black-and-white, which works just fine, as there would be no value in using color in the majority of the sample Web pages.

The author does an excellent job of explaining and illustrating all of the most commonly used and needed elements of the language. But he provides little guidance as to when a particular technique or approach should be used over another. For instance, when explaining how the programmer can use PHP to connect to a MySQL database, the author presents two alternatives -- direct layer and Pear::DB -- but no recommendations as to the choice of one over the other. On the other hand, one might argue that to include recommendations of techniques, as well as language best practices, would require the book to be much longer than it is, which would detract from the book's goal of getting a programmer up to speed on PHP in an efficient manner. The serious programmer who wishes to take PHP to the next level, can be expected to read more advanced books, to learn from expert PHP developers posting in online newsgroups, and to learn from experience as the programmer creates his or her own applications.

Another potential point of criticism could be that the book does not adequately explain how to use PHP with the various available database systems, only covering MySQL (the industry's favorite for use with PHP). But the database chapter, number 8, provides just enough information for the beginner to get started and to try out the basics. For simple database needs, the material in that chapter might be sufficient. Yet for more extensive MySQL usage, including installation and administration, other resources will need to be consulted. This book is clearly not intended to be one of those PHP + MySQL combo books that have proven so popular during the past few years.

The publisher's Web site for the book does not appear to have any collection of errata. Here are some that I found: On page 6, in the NOTE, "scripts can be used" should read "scripts cannot be used." On page 20, "#/ message to the user" should read "# message to the user." On page 49, in Table 2-4, in the last line, the formatting is partly wrong. Examples 3-1 through 4-14 contain incorrect indentation. On page 158, the last line in the $_FILES['userfile'] values is missing $_FILES['userfile']['error']. In Examples 5-19 and 5-20, the <head> and <h1> tags are missing ": Take 1." On page 169, the formatting of Example 6-2 is inconsistent with the others.

Aside from the errata, there were some other weaknesses -- none of them serious: The chapter summaries are useless, like in most other technical books, as there's not enough details to be instructive, and more details would make them even more redundant and space-consuming. On page 176, in Figure 6-6's caption, "Navigating" should be "Redirected." On page 197, the discussion of HTTP authentication is too brief to enable the typical reader to implement it. For instance, there is no mention of where to set $_SERVER[ 'PHP_AUTH_USER' ] to make it work. Chapter 7, on object-oriented programming and file handling, should be split into two chapters. Combining them makes no sense, and the author does not even transition from the first topic to the second.

Like others in the "Spring Into" series, this title is reasonably priced, at only $29.99 list for over 300 pages of quality material. The publisher, Addison-Wesley, has a page on their Web site devoted to the book, which includes a book description, a table of contents, an index, source code from the book, and a link for downloading a sample chapter (in PDF format), namely, Chapter 3, which covers strings and arrays. The site also has a link to a bonus chapter (also in PDF) that explains how to draw graphics interactively on a Web server and then send them back to the browser. Oddly enough, the page's title is "Spring Into PHP 5 - $20.99," but there's no indication as to how to get the book for only $20.99. That could simply be a typo. But there is a link to purchase the book online for $26.99. For those looking to spring into Web server-side development in general, or PHP in particular, it would be money well spent.


Michael J. Ross is a freelance writer, computer consultant, and the editor of the free newsletter for PristinePlanet.com. You can purchase Spring Into PHP 5 from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
This discussion has been archived. No new comments can be posted.

Spring Into PHP 5

Comments Filter:
  • wtf? (Score:2, Insightful)

    by Karaman ( 873136 ) on Thursday August 11, 2005 @03:04PM (#13297181)
    A professional programmer will never do the stupidity described in first paragraphs when dealing with new language and/or tool to perform task at hand. Although the book might be the best for beginners and advanced users, A PROfessional will not need it at all.
  • by jbdodson ( 815746 ) on Thursday August 11, 2005 @03:06PM (#13297199) Homepage
    I am not sure the addition of more OOP support is going to take PHP into the "less hackish" language camp in my mind. Moving from PHP development to a Java or Python/Zope based model with more emphasis on MVC patterns and Unit testing, is much better than the old hack way of putting all the controler, model and view code on the same page. I guess for a quick and easy solution, PHP got your back, I am not really in love with how it scales up if you want to move into MVC though. Plus the fact that it is a functional language at its core is not too appealing from a OOP perspective. Though, I use it to program my blog, go figure.
  • Re:I enjoy PHP ... (Score:4, Insightful)

    by Momoru ( 837801 ) on Thursday August 11, 2005 @03:11PM (#13297252) Homepage Journal
    or bring in ideas from Perl or C to my PHP code to make it look more advanced

    Who are you trying to impress? Why don't you just write whatever PHP you need to get the job done, no one cares if your code looks more advanced, it drives me nuts when people have this mentality in my office.
  • by joelparker ( 586428 ) <joel@school.net> on Thursday August 11, 2005 @03:12PM (#13297256) Homepage
    >A smarter approach is to learn the language basics in sequence as rapidly as possible

    In my experience a language becomes useful when you also learn the frequent idioms and know the available toolkits.

  • by mabu ( 178417 ) on Thursday August 11, 2005 @03:12PM (#13297262)
    A smarter approach is to learn the language basics in sequence as rapidly as possible, not getting bogged down in excessive sample code.

    Excuse me? Maybe I'm an anomoly, but I can't think of a better way to learn a language than by example. This suspiciously sounds like and excuse to cover up the fact that the book doesn't offer adequate material to show how one can code in real-world environments.

    When I look for a good programming book, be it an introduction, advanced tutorial or reference, the use of lots of examples is one of the main standards by which I judge the value of the publication.
  • by lukewarmfusion ( 726141 ) on Thursday August 11, 2005 @03:14PM (#13297282) Homepage Journal
    Let's see here...

    1. Professional developers are still creating websites using font tags and other deprecated nonsense.
    2. Programmers are writing extensive web applications entirely in Perl cgi, often taking months to do simple tasks that PHP or ASP can do in days.
    3. Existing sites are built on technologies that may be ten years old. They don't update their software every time a new technology, framework, or component comes out. They have to support old stuff in addition to building new stuff.
  • by bobbyjack ( 444724 ) on Thursday August 11, 2005 @03:15PM (#13297289) Homepage
    "Plus the fact that it is a functional language at its core is not too appealing from a OOP perspective. Though, I use it to program my blog, go figure."

    I figure that OOP is not the magic bullet many proclaim it to be. That some tasks fit the OOP model very well and others fit the functional model very well. And that PHP is a good language for certain applications, such as your blog.
  • by Christianfreak ( 100697 ) on Thursday August 11, 2005 @03:26PM (#13297383) Homepage Journal
    2. Programmers are writing extensive web applications entirely in Perl cgi, often taking months to do simple tasks that PHP or ASP can do in days.

    Myth #4349: Perl takes longer to develop than PHP

    Obviously you've never heard of CPAN or done anything more than pull some data out of a database and put it on a webpage. Anyone doing anything more than that on the web has to know something besides PHP since doing anything complex in PHP simply isn't very easy at all.

    Personally I really hope the PHP fad will be over soon since I'm not holding my breath for it to become a better language. ( PHP is barely better than 4. They still didn't fix some of the biggest beefs that many people have with the language ). Of course when it is over we'll all be subjected to the Next Big Thing (tm) instead of using something serious for once.

    (and I hope beyond hope the next big thing isn't Ruby on Rails)
  • by bobbyjack ( 444724 ) on Thursday August 11, 2005 @03:31PM (#13297434) Homepage
    "First, it has no mechanisms to enforce any kind of good web application design practices."

    Can you name me a language that DOES have "mechanisms to enforce any kind of good web application design practices"? I'm not sure I can think of anything built into a language (i.e. not just an add-on library which, of course, PHP could provide) that does do this.

    "Almost invariably, PHP apps are initially designed by people who are newcomers to programming and the web."

    I've seen many state this and have suspected it myself, but have never come across any good statistical proof. Can you post your reference?

    "But PHP doesn't provide any structure to help them make the right decisions,"

    Can you give an example of this? I'd be interested to see a language feature of [insert other language here] that "helps [newcomers] make the right decision".

    "so you end up with no separation between HTML and code, and you end up with an unmaintainable mess."

    But what's to stop this from happening in ANY language? And what's to stop it NOT happening in PHP?

    "Second, it's not a full-featured object-oriented programming environment like Java."

    I'll give the you benefit of the doubt, here, and assume you missed that oh-so-important comma. However, I'd argue that "not object oriented" is not a fundamental flaw of a language. Say we only had OO languages RIGHT NOW. Do you think everything would run quite as smoothly?

    "In Java, I can create objects, store them in sessions, hand them to threads, and store them using persistence frameworks. PHP has only the most rudimentary versions of such features."

    Good for you. What are the advantages of doing what you're doing that obsolete PHP in every instance?

    "Within a Servlet environment I can also create filters, something which doesn't exist in PHP."

    Please explain more - I don't know what filters are. I'd be very surprised if PHP could not support whatever-they-are.

    "There is hope. There are some tools like Smarty Templates and PEAR which help a little bit. In fact if beginners would force themselves to use Smarty Templates from the beginning they would get much better results."

    I'll have to get back to you on Smarty.

    "PHP doesn't have strong typing on variables, something which should be a part of any system that needs to be reliable."

    WHY? How strong is the typing in the language used to write the OS you're running right now?

    "There's no complition of PHP systems, which means that the only bugs are run-time bugs."

    Why is a smaller number of classes of bugs inherently a bad thing? Or is that just an objective statement?

    "PHP just isn't a good choice."

    For what? Why? I'm still not sure I quite understand.
  • by scottsk ( 781208 ) on Thursday August 11, 2005 @03:37PM (#13297507) Homepage

    I am not knocking this book by any means. It is probably very good. But can't any developer who knows a C-ish syntax language pick up PHP basics quickly? I learned it in a day or two just by analogy with C/Perl/etc. How much need/demand is there for entry level books like this?

    Where computer books have value to me is when they teach me something that would take hours/days/weeks to learn by trial-and-error. Something non-trivial that can't be guessed from reading the doc. (Like setting up user authentication or something.) That's when I start thinking about spending cash on books which have value by saving me time and especially frustration. (The PHP Cookbook, for example.)

  • by Eric604 ( 798298 ) on Thursday August 11, 2005 @03:40PM (#13297531)
    yeah but too much isn't good either. The last thing you want is crawling through pages of example code while it can be explained just as well in only a few lines.

  • by CyricZ ( 887944 ) on Thursday August 11, 2005 @03:47PM (#13297611)
    If your existing PHP4 setup is working fine, or at least acceptably, you may not want to transition to PHP5. It has been suggested that PHP 5.0.4 suffers from very poor memory usage.

    http://books.slashdot.org/comments.pl?sid=158685&c id=13297391 [slashdot.org]

    So at this point, it just doesn't sound like a transition may be a very good idea for a site that is already functional and running well.

  • Re:I enjoy PHP ... (Score:3, Insightful)

    by justMichael ( 606509 ) on Thursday August 11, 2005 @03:58PM (#13297737) Homepage
    So I always try to learn the more complex ideas around the language or bring in ideas from Perl or C to my PHP code to make it look more advanced...
    So you intentionally make your code hard to read/maintain so that you can justify your salary? If you really think your code "looks more advanced", chances are it's not.

    Is one of these more advanced than the other? Or does it just look that way to someone that's never seen a ternay operator before?
    if ($a == $b) {
      $c = $a;
    } else {
      $c = $b;
    }
     
    $c = $a == $b ? $a : $b;
    It's a much better plan to justify your existance to your employers by writing rock solid code that can be maintained by others when your l33t skillz get you a better job.

    There is also a huge difference between being able to write code in a given language and being able to write GOOD code in that language.
  • by DigitalBlossom ( 906945 ) on Thursday August 11, 2005 @04:05PM (#13297800)
    The only book anyone should be using for learning PHP is the PHP manual. We write it for a reason. The manual is the only resource I know of which is almost always up to date, maintained, and largely error free (We have errors, but as soon as they're reported they are fixed, usually within hours of the report being filed. Most of these types of errors involve spelling or gramatical mistakes.). Books released on the subject all do the same thing: re-write what the manual has already adequately stated while throwing in errors left and right.

    Arguably, there are a few books written which at first seem to be written well. Hell, who isn't tempted to pick up a book now and again which has names such as "Rasmus" and "Andi" etc stamped across the front in large gaping print. But these books are just as useless as those written by lesser-known authors, and shouldn't be used because of the same failings of other books: They're error-prone, and almost immediately deprecated. PHP changes rapidly, very rapidly. Possibly too rapidly for its own good, but that's another discussion entirely. Point being that you can't commit changes to the cvs repository of a book as you can to the PHP manual, and as such any printed book will fall far short of being as up to date as the PHP manual.

    If you need a resource to "teach you PHP quickly" there is generally only one chapter you need to read in its entirety, and that is php.net/langref. Anyone willing to take the time to do that can pick up the (extremely easy and basic) syntax of PHP within 2 to 4 hours. From there all one need do is hit the extension documentation pages of any API they may wish to use, such as php.net/mysql, php.net/pcre, etc.
  • by seek31337 ( 520238 ) on Thursday August 11, 2005 @04:07PM (#13297818) Homepage
    This is the most rediculously stupid comment I have ever seen. It makes a series of statements as fact, without any proof.

    It also makes claims of a solution which is incomplete. WTF? 'Would they even be willing to go so far as to demand that the PHP developers include functionality to severely limit the ability of faulty scripts to run?'

    Demand to make C programs unable to be hacked.
    Demand that perl programs are unable to be hacked.
    Demand that assembly programs are unable to be hacked.

    How about looking at the reputation of the group developing the software you morons install? If there's been tens or hundreds of vulnerabilities in the product you want to install, expect more!

    Also, see See http://us2.php.net/features.safe-mode [php.net]
  • I love PHP (Score:2, Insightful)

    by killermookie ( 708026 ) on Thursday August 11, 2005 @04:21PM (#13297942) Homepage

    I'm a huge PHP fan.

    But even I'm getting sick of these PHP reviews.

  • by Decaff ( 42676 ) on Thursday August 11, 2005 @04:41PM (#13298109)
    "In Java, I can create objects, store them in sessions, hand them to threads, and store them using persistence frameworks. PHP has only the most rudimentary versions of such features."

    Good for you. What are the advantages of doing what you're doing that obsolete PHP in every instance?


    Scalability. The ability to share objects and information between threads, so that they can be used throughout an application and not just within a request or session is vital for large high-performance websites. It is simply not practical to drop through to the database to reload information each time when you have hundreds or thousands of simultaneous users.

    "so you end up with no separation between HTML and code, and you end up with an unmaintainable mess."But what's to stop this from happening in ANY language? And what's to stop it NOT happening in PHP?

    In Java, for example, there are web development frameworks such as Tapestry, Struts and JSF, that have cleanly separated presentation and code layers. As for stopping it in PHP - that is tricky, as PHP was designed for HTML + code mixing.

    Please explain more - I don't know what filters are. I'd be very surprised if PHP could not support whatever-they-are.

    Filters allow specific ranges of URLs to have additional functionality wrapped around the requests. This is a highly useful feature, allowing things like post-processing of HTML, or checking authorisation (and diverting to error pages).

    There may be add-ins for this, but as far as I know, it is not standard for PHP, as it is in Java.
  • by maelstrom ( 638 ) on Thursday August 11, 2005 @05:57PM (#13298712) Homepage Journal
    The solution is to enable SELinux for Apache and only allow those PHP scripts access to their own files. Then even if there is an exploit for the poor written PHP code, the amount of damage it can do will be minimal.

  • by Anonymous Coward on Thursday August 11, 2005 @06:09PM (#13298779)
    It depends on what you want to learn. If you just need to quickly hack something then examples are great, but without learning the core of a language you you'll be limited to only being able to do the basic things seen in examples, and will have a hard time doing something novel. And without knowing the language you cannot judge the quality of the example you are copying.
  • by Anonymous Coward on Thursday August 11, 2005 @06:13PM (#13298803)
    PHP isn't functional, btw. It's procedural.
  • by Bogtha ( 906264 ) on Thursday August 11, 2005 @06:13PM (#13298810)

    the fact that it is a functional language at its core is not too appealing

    PHP isn't a functional language. It's a procedural/imperative language.

    I figure that OOP is not the magic bullet many proclaim it to be.

    Who has proclaimed OOP to be a magic bullet? Less of the straw men, please. I can't remember ever hearing anybody claim anything was a magic bullet seriously.

  • by Decaff ( 42676 ) on Thursday August 11, 2005 @06:18PM (#13298834)
    "It is simply not practical to drop through to the database to reload information each time when you have hundreds or thousands of simultaneous users."

    It is. I've worked on a site (NB: NOT my URL!) that handles greater traffic than that, with a large number of DB requests on a large proportion of pages. NOT written in PHP. But not even running on a box of its own ..


    It is not practical for anything but the simplest and smallest of data items. If it were, sites like E-Bay and high-volume stock markets would work like this. They don't.

    If you want a dynamic web site, you have to mix HTML with something at some point. It may be characters in a file, string delimiters, php delimiters, whatever.

    Yes, but what you don't want to mix is logic. Someone should not have to look through lines of HTML to see how you are doing a price calculation!

    Generally, web frameworks have specialised tags that are included in the middle of HTML to indicate where the results of processing are to be included.

    I don't see anything in the PHP language itself any different from any other language in this regard. HTML is just a bunch of strings; PHP can be written with nothing outside of the ?php ... ? at all.

    You can, but the mere fact you have those enclosing symbols indicates that the language was designed to allow embedding in HTML, and not to discourage it.

    "Filters allow specific ranges of URLs to have additional functionality wrapped around the requests. This is a highly useful feature, allowing things like post-processing of HTML, or checking authorisation (and diverting to error pages)."
    Forgive me if this sounds flippant, but isn't that something than can be achieved with an array, a regexp or two, and REQUEST_URI?


    It can, but why bother re-implementing this each time? Filter APIs allow Filter classes to be written in just a few lines of code.

    Is this something actually within the language itself?

    No. It is a standard part of the JSP/Servlet API, which is a subset of J2EE.
  • Re:wtf? (Score:4, Insightful)

    by tha_mink ( 518151 ) on Thursday August 11, 2005 @06:35PM (#13298930)
    Still, professional programmers probably don't use PHP at all - i've never met one who does.

    So then, all the enterprise PHP you see out there (that's right I said enterprise PHP) must be written by amatures?) So like...Yahoo is just a bunch of retards? [yahoo.com] Do you not notice how much of the really advanced web-apps are php these days? It's like some guy who writes machine code saying..."yeah....perl is just for dummies". Cmon Idiot!

    A better point would be that PHP is so easy to learn and flexable enough to do POORLY, that anyone with a logical brain, a book, and a text editer can "code" a simple widget.

    PHP is here to stay. Get over it!
  • by Decaff ( 42676 ) on Thursday August 11, 2005 @08:21PM (#13299630)
    That said, Ruby on Rails is amazing. If java isn't your bag, check it out. It has most of the best features of Java and PHP, almost none of the warts, and a whole bunch of great stuff you won't find anywhere else.

    After all your praising of Hibernate, how can you recommend this? Hibernate is an elegant and robust ORM that isolates your code from database specifics and allows you to write highly portable applications. Ruby on Rails requires exactly the kind of embedded SQL you don't like if you are to do anything complex, and makes your application extremely dependent on the database schema and the specific column names contained within it, and has serious barriers to portability.

    I agree strongly with almost every aspect of your post, but certainly not this last part!

Thus spake the master programmer: "After three days without programming, life becomes meaningless." -- Geoffrey James, "The Tao of Programming"

Working...