There’s an interesting challenge in writing a good book about programming. At a certain point, you’ll lose the newbies and alienate the technical. Below the line is a safe introductory book, above it is aimed at a smaller crowd. We had an opportunity review No Starch Press‘ Object-Oriented PHP, and found it fits nicely into the gap.
When PHP moved from version 4 to version 5, it introduced several new technologies to PHP programmers, chiefly SimpleXML, improved MySQL handling, SQLite, exception handling, and most importantly, a completely new object-oriented model. Making the switch to PHP5 is easy for most, as your old style will likely still work, but becoming proficient in using those new features evens the playing field and places many veteran PHP programmers back in learning mode.
Enter “Object-Oriented PHP” (No Starch Press, 2006). The subtitle of the book is Concepts, Techniques, and Code, which is fitting, because the structure of the book is such that it discusses a problem, shows ways to overcome them, and then gives you the code.
The book starts by discussing what objects are, why one might use them, and then examines general PHP object syntax. Many PHP 4 programmers have written volumes of procedural code and have never written a class in their life. The books seeks to dispell the myth that classes are too complex and for large IT shops only. I’ve personally found that some code is easier with object-oriented architecture and some code is easier and faster with regular procedural code. However, OOP is certainly handy when you need reusable and portable objects.
For example, a hypothetical function in your application might be fewer characters than the OOP alternative, but certainly writing code to iterate a directory is much longer, and when you use the code in several pages, it grows exponentially. Several examples of such behavior are explained in clear, easy to understand steps by the book.
Object-Oriented PHP covers several topics. Although the layout is logical and reads well, the content of the chapters is inconsistent. For example, the first four chapters are very broad – they covers basics and fundamentals of OOP. However, in the middle are chapters entitled The ThumbnailImage Class and Building the PageNavigator Class, of which are very specialized, very specific codes that only have meaning or value to some programmers. As a result, they are more fitting for O’Reilly’s “Cookbook” series than a book aimed at teaching you the basics of a programming concept. However, chapters such as Chapter 120 “Improvement Through Inheritance” and Chapter 11, “Advanced Objected Oriented Programming Concepts” cover, in detail, aspects of OOP that aren’t immediately obvious even to those who use basic classes and elementary OOP concepts.
Another important concept that those seeking better understanding of PHP OOP will appreciate is chapter 13, which details “Magic Methods.” This chapter discusses a lot of the “meat” of PHP objects, and includes several advanced concepts.
Object-Oriented PHP covers several subjects in detail, including touching on PDO or “PHP Data Objects,” new to PHP 5.1, which is so bleeding edge that even several months after press time, it’s rarely found on hosted servers. Learning concepts such as XML manipulation, discussed in chapter 12, SQLite, discussed in chapter 15, and PDO in the final chapter would prepare any level PHP programmer for inevitable changes and new capabilities that have been or will be introduced to PHP, and certainly many of these features will become more prevelent with PHP6.
Overall, Object-Oriented PHP is a good book that can teach even experienced PHP programmers how to add reusable objects to their code. The included code samples will certainly be useful, provided the scenarios outlined suit you. I would recommend this book to those migrating a PHP4 skillset to PHP5 and to those who are interested in a solid introduction and competance with PHP Object-orientation.
Pros:
Easy to understand
Provides solid foundation for PHP OOP
Discusses modern concepts such as SimpleXML and PDO
Cons:
Chapters vary between concepts and code with little warning
Included code is specific and may not be of use to you
Rating: 8/10
PHP Objects Patterns and Practice, which is the perfect book to shunt your PHP newbie up into some more grown up techniques. It includes OO, some useful core patterns, and basic introductions to things like source control, unit testing and build tools.
http://tinyurl.com/ezcqp (amazon.co.uk)
I agree. I read this book and found it pleasantly surprising and easy to understand. It also covers utilities “that help you document, manage, test, and build your PHP applications, including Phing, PHPUnit2, phpDocumentor, PEAR, and CVS.” (from the back cover)
Here is more information:
Title: PHP 5 Objects, Patterns, and Practice
Author: Matt Zandstra
Publisher: Apress
ISBN: 1-59059-380-4
Check it out if you are serious. I highly recommend this book if you want to move from procedural programming in PHP4 to the object oriented programming afforded in PHP5.
And please, don’t forget to pickup/research the topics of PHP security as well. Your code is only as secure as you make it.
Though i haven’t read it, i’m inclined to agree.
Having a good book go not only thru OO but how it relates to design patterns (and vice-versa) with some practical examples is a MUST for anyone wanting to go from the “relatively newbie” to designing real structured apps.
OO by itself is nice, but IMHO you can still do “spaghetti” code if you don’t get the real essence of it – wich is why i believe design patterns is a must-have.
I expected it would be a free ebook. Anyway, I like these books. I also recommend “Learning PHP5” from O’Reilly.
What constitutes “adformation?” Any product that gets a positive review? Or perhaps you’d rather not see reviews at all? Or better yet, perhaps you’ll buy the books and hardware and send them to us for review – you know, to create an unbiased ground zero. Sound fair?
We review products all the time, and I’ve never once been paid for work on OSNews.
Excuse me, Adam.
I agree with you, Adam. If you look at the comments both slight and I wrote above entitled See also…, you will notice how both of us were voted down for what I felt was insightful information. This wasn’t adformation, but rather our own personal opinions. I would’ve killed for this column and our types of comments when I was searching for a book covering this topic. Instead, I was forced to search online for (what I felt was) the best starting point.
I hope people can understand that when I post a reference to something, it is anything but advertising. Notice how I never even referenced a web link in my post. I left it up to the reader to perform their own additional research, giving them only a starting point to something that has helped me finally grasp the concept of object oriented programming and patterns.
So does this book focus on some of the special concerns of PHP?
Assuming a web system we have this to think about:
* Each class is parased, compiled and initialized for each and every request.
* The whole execution is geared towards a single request, and thus has no other concern other than to service this uniqe request.
* The execution is probably single threaded and is thus shielded froma alot of concurrency problems.
* Request data is availible in globals.
* Code in each layer can make theese basic assumptions about the execution.
In this environment there’s a whole slew of patterns and idoms coming from the Java-OOP world that just doesn’t make sense.
Edited 2006-10-06 21:11
According to PHP itself (the devs of course, not the language), the reason PHP 5 isn’t as popular as earlier versions with few upgrades is because it tries to go from a loose and very ill-structured language to something that more closely resembles traditional compiled programming languages.
PHP 6 will be almost fully OO, and as such, taken up by even less people.
If people want OO, they won’t use PHP. If they want something fast and powerful that gets the job done with minimum fuss they use PHP (no, not RUBY).
Just my two cents.
> If people want OO, they won’t use PHP
You’re crazy. OOP with PHP5 and MVC is the way to go, very clean and structured programming that is easily maintainable. What else do you want to use beside PHP? Maybe mod_python, but that’s it. Definately not JSP! (although it’s 100% OOP)
Yeah, *I* agree with you. But that’s besides the point.
If the OOP guys want to use PHP, that’s great.
But the fact remains, PHP’s OOP-direction for v6 and beyond *is* undeniably scaring away many people.
This isn’t me talking, it’s the numbers. Ask the PHP devs. I use PHP for OOP and you do too… But that scares the living shit out of a lot of others. OOP isn’t hard, it’s just perceived as being such by the n00bs and script-boys…