Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×

PHP Hacks 165

Michael J. Ross writes "Given the current popularity of the Web development language PHP, it makes sense that newcomers to the language have a large number of introductory and reference volumes from which to choose. But for the more advanced PHP programmer, there are far fewer titles that explain how to make the most of the language, by applying it to solve relatively substantial problems. One such book is PHP Hacks: Tips & Tools for Creating Dynamic Websites, by Jack D. Herrington. Read the rest of Michael's review.
PHP Hacks
author Jack D. Herrington
pages 468
publisher O'Reilly Media
rating 8
reviewer Michael J. Ross
ISBN 0596101392
summary Practical techniques and source code for improving PHP-based Web sites and applications.


The book was published by O'Reilly Media in December of 2005. Despite its title, PHP Hacks: Tips & Tools for Creating Dynamic Websites is clearly intended to show how PHP's capabilities can be extended beyond its most common usage for creating dynamic and database-driven Web pages, and can be employed in such areas as graphics, reporting, Web site testing, code generation, and even fun purposes (for those few programmers who find the former topics less than entertaining). The author, assisted by six contributors listed in the Credits section, manages to pack an impressive number of general programming ideas and PHP-specific topics within this title's 468 pages. The material is grouped into 10 chapters, each of which contains a generous number of "hacks," each in its own section.

As with most if not all of the other titles published by O'Reilly, this book has a Web page that offers an overview of the book, its table of contents, all of the book's code (in both Zip and tar file format), and a list of confirmed and unconfirmed errata. In addition, the site hosts five sample hacks (in PDF format): accessing iPhoto pictures, generating Excel spreadsheets, avoiding the "double submit" problem, reading RSS feeds on your PSP, and creating custom Google Maps. Perusing these hacks would give the prospective buyer a clear sense as to the style of the book's other 95 hacks, as well as the (low) level of PHP expertise needed to understand them.

The book begins with a preface that describes the organization, conventions, and icons chosen for the book. Also, it covers the legality of the code samples, lists contact information, and mentions O'Reilly's Safari online book service, which contains this title among many other PHP resources. What is perhaps most unique about this book's preface is that the author identifies over half a dozen weaknesses commonly seen in PHP applications, and explains how his book addresses those problems. In addition, he makes explicit how some of the hacks can be used for jazzing up one's Web site or Web-based application.

The first chapter discusses how to install PHP on Windows, Mac OS X, and Linux, and then verify that the installation was done properly. Herrington then briefly explains how to install MySQL and perform some basic database management. The chapter concludes with coverage of installing the PEAR library on your local machine and on your Web host's server (which is incorrectly identified as your "ISP machine," apparently assuming that most developers choose their Internet service providers for hosting their sites, when in fact the opposite is true). Since the typical reader of a non-beginning book such as this no doubt has one or more introductory and/or reference PHP books at hand, it would seem superfluous to waste time and space explaining how to install these components. But few pages are taken up by the material.

The next chapter is devoted to hacks that help to jazz up the design of one's Web sites, including how to create a skinnable interface, build a breadcrumb trail, create HTML boxes, add tabs to your interface, and other valuable techniques. Subsequent chapters offer hacks in the areas of dynamic HTML (DHTML), graphics and digital pictures, databases and XML, application and e-commerce design, patterns and PHP object orientation, testing and documentation generation, and building alternative user interfaces. The 10th and final chapter covers some "fun stuff," such as creating dynamic playlists, developing a media upload/download center, and even putting Wikipedia on a Sony PlayStation Portable.

Rather than try to explain in detail all of the many topics covered in the book, I instead encourage the interested reader to visit the publisher's Web page, and scan through the table of contents provided, to get a better idea as to how much of the book would be of interest to the individual. Also, the five sample hacks listed on the site, would be well worth examining and trying out. Overall, the topics chosen reflect favorably upon the judgment of the lead author and the other contributors to the book. The typical PHP veteran would likely be interested in most of the applications covered, and would probably learn some new tricks, especially in the areas of patterns and code testing, regardless of their level of experience.

Like all books, this one is not perfect. As with the first printing of most technical books; particularly those chock-full of source code; the book contains a fair number of errata, likely even greater in number than those reported and listed on the publisher's Web site, as mentioned earlier. Consequently, any reader who chooses to test the sample code and he or she would be encouraged to do so; should keep one browser window or editor buffer open and devoted to those errata, so as to minimize the time spent trying to figure out why some sample code is not working as advertised.

Some readers posting in forums have complained that the sample code has evidently not been fully tested on all platforms, nor in all Web browsers. Since few if any reviewers would have the time, resources, or inclination to verify these claims, it should suffice to simply bear in mind that the script output and other behavior detailed in the book might not exactly match those experienced during one's own usage of the code.

The fact that there were several cooks in the kitchen brewing up this particular book, is obvious from the way that the code formatting is not consistent throughout the book, as well as the variety of problem-solving styles. Fortunately, neither weakness is of much consequence, and the latter might even be considered a "feature," as it allows the reader to see how a number of veteran PHP developers approach solving a problem.

Most technical works written by a team of authors, end up as excessive "doorstops" that are often frustrating to read as a result of the wildly inconsistent writing and coding styles, to say nothing of the material often being out of date as a result of the long production time needed by the publisher. The opposite case can be even worse, when a publisher releases a book that was clearly thrown together as quickly as possible to capitalize upon a hot new trend in technology. Thankfully, PHP Hacks keeps the style differences to a minimum, and benefits from having a lead author responsible for the book as a whole.

Some programming purists may take issue with the use of the term "hack" used as a synonym for a small PHP application or the use of such for solving a problem, since the majority of the PHP scripts in the book do not involve any programming or problem-solving that would be considered notably clever or elegant. Yet the misuse of the term seems to be spreading, and is not limited to this particular book ; another example of marketing overpowering stability of language. In the preface of PHP Hacks, the author explains that he uses the term in the positive sense of creative participation, to help reclaim it from its popular usage in place of the more traditional term "cracking," i.e., breaking into systems.

Yet aside from these complaints, PHP Hacks is a worthy title that offers explanations and source code for many valuable site-enhancing applications, testing and code generation techniques, and critical e-commerce safeguards. I recommend this book to any PHP developer who would like to add to their Web sites' capabilities, as well as their knowledge of what PHP can do.

Michael J. Ross is a freelance writer, computer consultant, and the editor of the free newsletter of PristinePlanet.com."


You can purchase PHP Hacks: Tips & Tools for Creating Dynamic Websites 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.

PHP Hacks

Comments Filter:
  • by Anonymous Coward on Wednesday July 05, 2006 @05:11PM (#15662991)
    Yet again Slashdot links to BN.com for kickbacks when Amazon has it cheaper [amazon.com].
  • I'll try (Score:1, Informative)

    by Anonymous Coward on Wednesday July 05, 2006 @05:43PM (#15663209)
    I believe the article author is talking about licensing of code samples. That's always a problem with some books, there's no license for the sample code, so you have to if it can be used in any project or none at all. Having a clear explanation for using the sample code is sometimes nice when you're dropping some code from an example into your code to fix a problem you've been having.
  • by chromatic ( 9471 ) on Wednesday July 05, 2006 @05:57PM (#15663280) Homepage

    Draw whatever conclusions you like, but the linked page is accurate.

  • by FooAtWFU ( 699187 ) on Wednesday July 05, 2006 @06:19PM (#15663390) Homepage
    It's all true. Now, I know Perl has its own set of issues, and as far as speed is concerned you can't expect plain vanilla CGI to favorably compare to decently cached PHP in a DSO module for Apache (though you CAN run spiffy-fast with things like mod_perl or FastCGI, especially if you're willing to leave Apache for lighttpd like the Ruby on Rails people like). And of course you can write some really incoherent stupid code in Perl, certainly -- especially when you're not smart enough to realize there's something nice in CPAN or your standard Perl distribution that already does what you're asking. But you can also write simple, clean, beautiful, elegant code to do amazing things (and I will always love my hash of anonymous coderefs :)

    PHP is the Windows of web programming. It's simple (on the surface), extremely prevalent, trivial to get started with... and then it's inflexible, promotes droolingly bad design decisions, and has a security layer full of holes.

  • PHP Popularity (Score:2, Informative)

    by hotfireball ( 948064 ) on Wednesday July 05, 2006 @06:54PM (#15663557)
    "Everything populair is wrong" -- Oscar Wilde
  • by FooAtWFU ( 699187 ) on Wednesday July 05, 2006 @07:03PM (#15663597) Homepage
    Well, of course you can write solid code in PHP. You just need to plug all the security holes yourself, explicitly. I, for one, would like to have prepared statements deal with escaping parameters, not have to worry about the fourth parameter of mail() turning my form into a spam machine... and if you've never used add_slashes - are you relying on magic quotes? Is that script of yours supposed to be portable? Sorry.
  • by VGPowerlord ( 621254 ) on Wednesday July 05, 2006 @07:26PM (#15663698)

    I don't see why everyone is so critical of PHP.

    PHP started out as a set of Perl scripts in 1995, presumably using the then-new Perl 5. When it became its own language in 1997, it somehow lost namespaces, the module loading system, DBI, use strict, and everything else in Perl that doesn't register on the suck-o-meter. It also did silly things like adopt the TCL global variable system, rather than using the one that C, Perl, Java, and even things like VB use.

    So, yeah, there's a reason every is critical of PHP.

    Sources: perldoc perlhist [cpan.org] (perl 5.000 was released on 1994-Oct-17), PHP History [php.net] (PHP/FI 1.0 was a bunch of Perl scripts released in 1995, PHP/FI 2.0 was written in C in 1997), DBI::Changes [cpan.org] (First official DBI release was 0.58 released in 21 June 1995)

  • by no_barcode ( 840948 ) on Wednesday July 05, 2006 @07:31PM (#15663716) Homepage
    Strings will not be broken in PHP 6. Most of the changes that might cause older applications or current applications taking advantage of deprecated functions to fail have had years to make the changes needed to prevent such failures and/or abnormal program terminations. http://www.corephp.co.uk/archives/19-Prepare-for-P HP-6.html [corephp.co.uk] http://wiki.cc/php/PHP6 [wiki.cc]
  • Re:You do (Score:3, Informative)

    by Mattintosh ( 758112 ) on Thursday July 06, 2006 @07:15AM (#15665937)
    Object orientated programming

    Maybe I'm just elitist, but why would you make all of your objects face eastward? [m-w.com] Oh, you meant object oriented [m-w.com] programming.

    The web is growing up, and page processors like PHP will fall out of use. WebObjects showed the way forward arbeit at a cost of $50,000 when it was 1st released, and now we have free alternatives like Jakarta/Struts and Ruby on Rails.

    The web hasn't changed. It's still a stateless, every-page-for-itself environment. PHP isn't a "page processor", it's a pre-response request processor. A client sends an HTTP request (yes, the very same as the XmlHttpRequest JavaScript "object") to Apache (Apache HTTPD, to be specific). Apache uses PHP (as mod_php) to preprocess the request. Then Apache sends the response generated by PHP. That's why PHP (now) means "PHP Hypertext Preprocessor".

    "Jakarta/Struts" is a framework (actually probably several frameworks) built in Java and uses the Tomcat engine to serve up servlets. Guess what... A client sends an HTTP request (all the URL's start with "http:" regardless of the port, so it's still HTTP) to Tomcat. Tomcat uses Java (and it's libraries and frameworks - like Struts) to preprocess the request. Then Tomcat sends the response generated by Java. I feel like I'm repeating myself here.

    [JavaScript is] a great OO language, highly dynamic.

    You have got to be kidding me. JavaScript is a prototyped language. You don't define objects so much as you lay out a template for one and implement a library that pretends to operate on this so-called "object". It's about as OO as old-school C. In C, you could define a struct and segregate off a header and implementation for it and call it an "object", but there was no enforcement other than internal constraints you imposed upon your own code. JavaScript is just about as strict.

    It's possible to do some serious development in Javascript.

    I've been wondering what was wrong with web design lately. I've also been wondering why everyone on /. bitches incessantly about the evils of "web apps". Now I know. I can tell you one thing for sure, though. It's possible to do some serious development in JavaScript... just turn it off. That's the best development JavaScript has seen in years.

    I'm happy that the patterns for web development are finally moving closer to the 1980s.

    Keep using JavaScript and you'll keep moving toward the 1980's. Meanwhile, the rest of the world will continue going forward.
  • by klagg ( 107206 ) on Thursday July 06, 2006 @09:36AM (#15666521) Homepage
    I'm not trying to defend the inconsistencies in PHP (you are right there), but if you feel you need to look at the manual all the time you need to use a better tool. Zend studio, for example, autocompletes function names and also tells you in which order to put the arguments. This is a huge timesaver if you're using PHP.

The moon is made of green cheese. -- John Heywood

Working...