I finished the third book from my PHP reading list now, “PHP for absolute beginners”, by T.B. Hansen and J. Lengsdorf. And this one is my favorite of the three!
This book just like the “Head First” book does everything right in terms of starting practical, giving you a real world example you can try out from chapter one and then adding complexity. It’s the thinnest book of the three, only 200 pages, which makes it easy to get a full overview quickly.
In terms of content, it begins with explaining the XAMPP stack (X as a wildcard for any operating system, then Apache, MySQL, Perl, PHP), and then covers the same basics as every other book: HTML & CSS pages, forms, MySQL database…
Comparing this book with the previous one, I cannot overstate how important it is to begin with the Why! We have two books covering nearly the same content; one is a pleasure to read, because you see the motivation and then you get thought only so much theory as you need to solve the immediate problem. The other one is horribly boring to read, because it explains concept after concept and you don’t see where this is going.
Now, having talked about why that book is way better for a programming beginner, let me summarize what I learned new in this book:
- It introduces the MVC (model – view – controller) pattern early and demonstrates how you should follow this pattern by seperating you code into files that are included by one central front controller
- It explains that this book will not use any framework, but the frameworks that there are also follow the MVC approach
- It suggests to use PDOs (PHP data objects) to connect to the database. Coming from a JavaEE/Spring background, it feels weird for me to pass the database connection to an entity object and let it handle it’s database operations itself, but it’s interesting to learn that this style is used in the PHP community.
I still dislike PHP for missing compiler-enforced type safety and encapsulation; as far as I have seen, separation of code into different files is cosmetic, while using another file (“include”) the code of the second file gets just plugged in the first one, making state kind of global instead of encapsulating it. But with the MVC pattern and a front controller it feelds already less hacky than the loose collection of PHP script files I have seen before, and I start to believe one can eventually build robust, maintainable applications with that language. (Assuming that there is also unit test automation in PHP, which I haven’t yet read about in any of the books.)