Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



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

Learning PHP 5 201

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.

This discussion has been archived. No new comments can be posted.

Learning PHP 5

Comments Filter:
  • by ptlis ( 772434 ) on Thursday October 28, 2004 @05:41PM (#10657992) Homepage
    It runs on something other than IIS...
  • Back in my day... (Score:5, Insightful)

    by sleighb0y ( 141660 ) on Thursday October 28, 2004 @05:45PM (#10658026) Homepage
    We would learn PHP from the php.net documentation alone!

    And we liked it that way!
  • by Anonymous Coward on Thursday October 28, 2004 @05:54PM (#10658098)
    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...

    So, being open-source is more important than suitability to task?
  • by EZmagz ( 538905 ) on Thursday October 28, 2004 @05:55PM (#10658109) Homepage
    With a language like PHP that has a very active developer community associated with it, why plop down for a book like this when websites like THIS ONE [php.net] exist and give all the documentation that you'd need when learning the language? I realize that it's handy in having a hardcover book to read (hell, I've got my fair share right next to my unemployed ass) and reference...but still.

    Just curious.

  • by colinramsay ( 603167 ) on Thursday October 28, 2004 @06:02PM (#10658168) Homepage
    Absolutely not. ASP is a scripting language. PHP is a scripting language with string OOP features. ASP.net is a framework for the web, which allows you to use a fully featured OOP language such as C#.

    To be honest, if you've never used ASP.net, then it is difficult to explain the differences. But for the web, nothing else comes close.
  • by ptlis ( 772434 ) on Thursday October 28, 2004 @06:03PM (#10658176) Homepage
    php.net is a wonderful reference, even for people who have only the most rudimentary understanding of how to use php but for a total newbie I can see how it could be very daunting; I personally began my way with php scripting by downloading a few pre-made scipts (for an automagically generated image gallery iirc) and realising that none of the three I had grabbed worked and there were features that if worked I would like from each. So I did the obvious thing and (looking up stuff on php.net) cobbled them together into a working set of scripts; problem with this route (and self-learning in general) when compared to traditional/book learning is that not knowing any better you get into some bad habbits which may (and im my case did) come back to bite you when you're more knowledgable. Additionally in getting something to 'just work' you may kludge together some funky code when there's a much easier way you could have done it if you'd read around the subject... I think i've rambled enough but the jist of it is that php.net is an awesome reference if you can't remember the syntax for something but is far from ideal for a newbie trying to learn the language.
  • Re:PHP or Perl? (Score:3, Insightful)

    by gentoo_moo ( 679483 ) <cetzel@ g m a il.com> on Thursday October 28, 2004 @06:09PM (#10658226) Homepage
    My first programming was in Perl. It was akward but fun. I switched to PHP about a year after I started Perl. I picked up the basics of PHP in about a week. Perl took me a bit longer (like a month for the fundamentals - but I was a real newbie too). Inside two weeks of geeking on PHP I'd written a service ticket program for my private consulting business, did some freelance web coding for another firm and wrote a small checkbook (quicken clone) to get used to it with MySQL.

    After about 3 months of playing with it, I wrote a web-based tracking system that my company uses to manage service calls and billing.

    I think you'd probably pick up PHP pretty quickly. Others may say the same about Perl. This is just my humble opinion.
  • by Anonymous Coward on Thursday October 28, 2004 @06:21PM (#10658310)
    It is for me.

    If it's open source and clumsy, it will can always evolve into something better. If it isn't, well, they got your money once, and you better be happy.
  • by eln ( 21727 ) on Thursday October 28, 2004 @06:35PM (#10658427)
    I've been programming perl for almost 10 years now. 2 years ago, I got a job where the entire codebase was in PHP. Because of my extensive knowledge of perl, I was able to pick up PHP good enough to become one of the top PHP coders on the team within about 2 weeks.

    Honestly, PHP is MUCH better than perl if you want to write web applications. I still use perl for anything that I need to run from the command line, but for web stuff, it's PHP all the way.

    Now, PHP does have some pretty significant flaws, and perl does a lot of stuff far better than PHP, but PHP is so far superior at doing web-related things that it's silly to write web applications with perl instead of PHP, unless there is some functionality that app depends on that PHP just can't do at all.

    By the way, saying you refuse to even look at another language because the language you use is so damn cool makes you a zealot, whether you want to admit it or not. Any good programmer should be willing to investigate and learn new languages. Nearly every language has its niche where it is better than any other language at doing whatever it does. With PHP, that niche is web applications.
  • by Anonymous Coward on Thursday October 28, 2004 @06:37PM (#10658446)
    Perl does more than produce webpages via mod_perl. It is a powerful general purpose scripting language. PHP is not. PHP was built to spit out html and that is what it is good at.
  • by Anonymous Coward on Thursday October 28, 2004 @06:41PM (#10658477)
    Its version number is the same as Perl
    Next time you should leave that part out, it's quite irrelevant and completely superficial.
  • Re:PHP or Perl? (Score:2, Insightful)

    by phek ( 791955 ) on Thursday October 28, 2004 @06:59PM (#10658614)
    Saying perl is 10x faster than PHP is really misleading. Bad PHP may be 10x slower than bad perl, but from my experience good PHP, is just about as fast as good Perl. The thing is PHP just try's to bring over so many functions from other languages, it can be really slow if your using something like the python derived functions. If you try to code PHP like you code C though, PHP tends to be around the same speed as Perl.
  • Job Lobby (Score:2, Insightful)

    by Line_Fault ( 247536 ) on Thursday October 28, 2004 @08:15PM (#10659153) Homepage
    I love PHP5! I've been running it since the first beta!
    Now if only I could find a job writing it!

    It seems most of the jobs here are ASP related mostly because Microsoft actively sells their product, there is no one selling Free alternatives.
  • Re:PHP or Perl? (Score:2, Insightful)

    by downward dog ( 634625 ) on Thursday October 28, 2004 @08:43PM (#10659294) Homepage
    Are you really recommending C for web programming (which is 95% of PHP's use)? Unless you're writing Amazon.com, you will spend FAR too long programming and receive little perceivable benefit. PHP is perfect for most web programming; a shopping cart doesn't need to be uber-efficient. Few web apps peg the processor on their server. And if they do, it is not going to be PHP code that will do it -- it will be database or HTTP.

    Not saying that C isn't a great language for some things, but it is not a great language for rapid development of complex web applications. :)
  • by Ogerman ( 136333 ) on Thursday October 28, 2004 @09:39PM (#10659589)
    What advances does PHP5 make that puts it in direct competition with ASP.NET?

    PHP5 competes with ASP.NET (and Java) up to a certain point. This is a question of best tool for the job. PHP5 is great for developing interactive websites, CMS/forums/blogs, and other lightweight web applications as suitable for an inexpensive hosted environment. However, PHP5 is still way behind today's Java and .NET platforms for developing enterprise (aka. complex, database-heavy) applications -- whether for the web or otherwise. In many cases, PHP is legitimately the "simplest thing that could possibly work" and is thus an excellent choice. However, the architecture that makes PHP great for RAD and simple web applications also severely limits its usefulness for more complex applications. I say this not off-the-cuff but entirely from real-life experience.

    So it comes down to this: if your application is simple enough, by all means use PHP5. It is a great tool for limited-scope jobs (analogous to VisualBasic for the web perhaps) and its performance and scalability is excellent given its limited-by-design architecture. Simplicity on the low end is PHP's strength.. it doesn't try to do too much for those who don't need it to! On the other hand, if your application is more complex (most business apps, anything accounting / finance related, mission critical databases, etc.) use a modern, lightweight, framework-driven Java approach like Spring + Hibernate. PHP is no longer the "simplest thing that could work" when the application domain has moved beyond what it naturally does well. You can force the use of just about any language for any given task but that doesn't mean it makes sense to. (and spare me the silly politics..)

    Choice is good. What does disturb me is how many open source programmers today think that PHP, Perl, and Python are the answer to everything web-related. They're not. I could name a few dozen projects currently using those language that would be far better off using Java instead. Incidentally, Python is the closest to competing directly with Java's domain, but needs a few more years for its tools to mature.

    http://www.extremeprogramming.org/rules/simple.h tm l
    http://www.springframework.org
  • by Davorama ( 11731 ) on Friday October 29, 2004 @02:38AM (#10660950) Journal
    Well, it's not really that hard in PHP either.
    function cmp($a, $b) {
    return strcmp($a[1], $b[1]);
    }
    $a = array(array(1,3), array(2,2), array(3,1))
    usort($a, 'cmp');
    print_r($a);
    So I guess we have passed the smell test here even if I did obfuscate my code with bad variable name choices. I don't feel too bad about it since you made me read python ;-p.

    Now the real question is how do I get /. to indent my code properly?

  • Re:PHP or Perl? (Score:3, Insightful)

    by LordLucless ( 582312 ) on Friday October 29, 2004 @04:13AM (#10661225)
    If you really want the ultimate in execution speed, efficiency and flexibility, code everything in assembler. If you see anything you like in a PHP script, simply re-invent the whole thing from scratch.

    If, on the other hand, you are not a masochist, you want to write something quickly and easily, something relatively easy to debug, something that isn't going to get multiple hits per second - use PHP. That's what it's there for.
  • by D-Cypell ( 446534 ) on Friday October 29, 2004 @07:17AM (#10661722)
    I just want to apply a virtual +1 to this post.

    There is a very subtle line in the sand where PHP becomes 'underkill' and you need to consider moving to a more rounded technology like J2EE or (*spit*) .Net. Experience is knowing where this line is (or better still knowing that the product being developed will cross it in X amount of time).

    There are far too many people using J2EE and .Net style techs for things where PHP would be (and would remain indefinately) the much better choice.

    Also, the other way around, but this seems much rarer...
  • by ralphch ( 772571 ) on Friday October 29, 2004 @09:15AM (#10662262)
    and having coded all my web applications in Perl, until recently, I decided to implement PHP on a fairly lightweight Bookfair system. I built it using a complete OOP framework and it's running amazingly well. As for the overbloated PHP design (twenty functions for the same thing), I hear you. All I can say is keep consistency in your code, limit yourself to a handful of functions. And hope, eventually, PHP will mature even further. Then again, it's mostly about 'how' you code rather than 'what' you use to code.

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

Working...