Reddit Reddit reviews PHP 5 Objects, Patterns, and Practice

We found 10 Reddit comments about PHP 5 Objects, Patterns, and Practice. Here are the top ones, ranked by their Reddit score.

Computers & Technology
Books
Networking & Cloud Computing
Internet & Telecommunications
PHP 5 Objects, Patterns, and Practice
Used Book in Good Condition
Check price on Amazon

10 Reddit comments about PHP 5 Objects, Patterns, and Practice:

u/soadapop · 11 pointsr/PHP

Probably the best book I've read on this matter is PHP 5 Objects, Patterns, and Practice. It will bring you through the basics of OOP in PHP all the way to the advanced goodies found in patterns and practices.

Many of the patterns found in the book are cornerstones for the plethora of MVC frameworks out there and I feel that anyone who has a good understanding of the material in this book will be just fine out there in the real OOP world.

Also, checkout out this really good aggregate of a bunch of web development (mainly PHP) topics and articles.

u/[deleted] · 5 pointsr/PHP

mmm...I like Rob Allen's dev notes (he also has a pretty good book called Zend Framework in action, which of course is very ZF oriented, but that's not a bad thing if you're looking to learn some good practices). Also, PHP 5 Objects, Patterns and Practices is a pretty cool read.

u/farsightxr20 · 4 pointsr/PHP

I'd suggest finding a newer book as soon as you can. This example is riddled with bad practices, and it's best to avoid forming bad habits instead of trying to break them later.

Some things that jump out at me:

  1. The shut-up operator (@) shouldn't ever be used. It's slow, and makes debugging a pain in the ass.
  2. While using "or die()" might be adequate for a quick and dirty script, it's never a good idea to simply exit a program because an error has occurred. Look into Exceptions for error handling.
  3. The mysql_* functions are dated and shouldn't be used. Use instead PDO (with prepared statements) (highly recommended) or mysqli. Mysqli has procedural methods similar to the ones in your example, but you need to be careful to escape all of your user-inputted values with mysqli::real_escape_string or mysqli_real_escape_string

    My personal recommendation would be PHP 5 Objects, Patterns, and Practice, as it will teach you stuff you should know about programming in general, as opposed to simply PHP syntax.
u/aaarrrggh · 4 pointsr/PHP

Cool, well if you're serious, this is a very good book: http://www.amazon.co.uk/PHP-5-Objects-Patterns-Practice/dp/1590593804

It can be a little dense at times, so I'd read it carefully and definitely try out some of the examples as you go along with it.

For me, the whole OOP thing didn't really 'click' until I understood the real usefulness behind interfaces and abstract classes (basically, polymorphism). It's something that I just didn't get, and I'm talking about having been using classes and objects for over a year without understanding why an abstract class would ever be a good thing.

Polymorphism is one of those things that I'd read about before but just couldn't quite "get". It's one of those things that I just didn't click with until I came across a problem in a real world situation that could benefit from it. I had a go with it and suddenly a whole new world opened up.

So here's the problem: I was asked to output csv based reports from our system at work. It was clear from the initial meeting that there would probably be other reports coming in the future, and some of these might be in different formats such as json or even excel.

Here's where some of the key differences between OOP and the traditional (almost always messy and unorganised) PHP mentality really come to shine.

Instead of explaining the underlying theory behind it, let me show you the end result first:

I ended up with a system that could create new reports really easily. As soon as a new report was created, it was INSTANTLY available in csv, json or excel format, and I had an absolute guarantee that adding a new report would not break anything in my existing system.

Here's some typical use cases:

  1. Create a daily summary report in csv format:

    $report = Library_Factory_FinancialReports::create(Library_Factory_FinancialReports::DAILY_SUMMARY_REPORT);
    $writer = new Financial_Report_Writer_Csv();
    $writer->write($report);

  2. Create the same report in json format:

    $report = Library_Factory_FinancialReports::create(Library_Factory_FinancialReports::DAILY_SUMMARY_REPORT);
    $writer = new Financial_Report_Writer_Json();
    $writer->write($report);

  3. Create a monthly financial report in excel format:

    $report = Library_Factory_FinancialReports::create(Library_Factory_FinancialReports::MONTHLY_FINANCIAL_REPORT);
    $writer = new Financial_Report_Writer_Excel();
    $writer->write($report);


    Do you see how easy that is?

    This is achieved through polymorphism and abstract classes.

    Whenever you want to create a new report, you simply create an object called a 'ReportReader'. This object ALWAYS returns it's final data in a set format, so the writer objects can understand them. They will always be compatible. For this reason, I can write a writer object just once, and so long as it works, it will work with all reader objects, and vice versa. I want to create a new format for my reports? Just create a new writer, and once it's finished, ALL reports will become available in that format. Want to create a new report? Just create a new ReportReader object (this object is what is set to the $report variable above - it's returned by the Library_Factory_FinancialReports::create() factory method), and this report will instantly be available in ALL formats that are available in the system - and even better, it will never touch any existing code (except to add a couple of lines to a switch statement in the Library_Factory_FinancialReports::create() method to return the correct ReportReader object).

    I can test each class independently and I can add and remove things with ease.

    This is due to polymorphism.

    I can explain it a bit further if you want... It basically comes down to thinking about problems in a more abstract way, and then working out a common interface that can be guaranteed between all objects...
u/code_guy · 3 pointsr/PHP

Then PHP-5-Objects-Patterns-Practice is for you. PHP is know as a "kids" and "insecure" language, because so many people do php the wrong way. I'm not saying there is a right way, but there sure is a wrong one.

After reading first two chapters, learn a little about http protocol. Since you are programming in C i assume you have some knowledge with network programming and sockets, if yes it will be really easy to understand basics. If you didn't program with sockets, do that (it's really fun, you can create you own server, listen on that port and create a web application with C ).
After you get familiar with http ( pay special attention to POST and GET ) you can start working on home projects, learning HTML in the process ( it's really easy so i won't post anything about it here ) and using knowledge you used in first book to design a good app. Also manual is amazing, if unsure about something go there.

This is a proper way to do PHP, so you actually know what you are doing. If you want to just build web apps and don't care about anything ( and continue to contribute to myth that php is "xy" language ) do just that.


Protip: Go the hard way.

u/kson34 · 1 pointr/PHP

For PHP I would definately recommend PHP 5 Objects, Patterns and Practice. Pro PHP Refactoring is also pretty good. And the latest book on PHP Security is good too.

For javascript I would start with the Good Parts, go to Javascript Enlightenment and read what is available in EAP for Secrets of the Javascript Ninjas because although the book may never actually be finished what is there is worth 30 average javascript books.

u/xnoise · 1 pointr/PHP

There are a ton of books, but i guess the main question is: what are you interested in? Concepts or examples? Because many strong conceptual books are using examples from java, c++ and other languages, very few of them use php as example. If you have the ability to comprehend other languages, then:

http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=sr_1_1?ie=UTF8&qid=1322476598&sr=8-1 definetly a must read. Beware not to memorize it, it is more like a dictionary. It should be pretty easy to read, a little harder to comprehend and you need to work with the patterns presented in that book.

http://www.amazon.com/PHP-5-Objects-Patterns-Practice/dp/1590593804 - has already been mentioned, is related directly to the above mentioned one, so should be easier to grasp.

http://www.amazon.com/Patterns-Enterprise-Application-Architecture-Martin/dp/0321127420/ref=sr_1_1?ie=UTF8&qid=1322476712&sr=8-1 - one of the most amazing books i have read some time ago. Needs alot of time and good prior knowledge.

http://www.amazon.com/Refactoring-Improving-Design-Existing-Code/dp/0201485672/ref=sr_1_4?ie=UTF8&qid=1322476712&sr=8-4 - another interesting read, unfortunatelly i cannot give details because i haven't had the time to read it all.