Good Training Sources for OOP PHP, Anyone? - php

I will like to see if everybody could share any good training sources on OOP on PHP language.
Good Training Sources for OOP (Object Oriented Programming) PHP, anyone ?
I've seen numerous tutorials, mostly superficial, some of them bad.
Please share anything good either commercial or free, Video or Written.

I love the PHP Manual's guide to OOP. It's to the point and has many examples.

This is your absolute best bet, in my opinion. The documentation here includes both technical explanation as well as useful examples and plain-english wording.
PHP.net/oop
Keep in mind however that PHP OOP is still in relative infancy, and there will no doubt be many things that are confusing to other OOP implementations.

Lynda.com have a good video course:
Lynda - PHP with MySQL Beyond the Basics
http://www.lynda.com/home/DisplayCourse.aspx?lpk2=653

It's a bit more on the advanced side of OOP, since it's about design patterns, but I really like Martin Fowler's Patterns of Enterprise Application Architecture (http://www.amazon.com/Patterns-Enterprise-Application-Architecture-Martin/dp/0321127420/ref=sr_1_1?ie=UTF8&s=books&qid=1255402272&sr=1-1). And you can never go wrong with the Gang of Four's pattern book (http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/)
The nice thing about learning patterns is that they're language agnostic. Learn a pattern, use it in (almost) any language :)

For starting the php phpmaual is the best thing that is available.
You can also try http://w3schools.com
If you wants some more resources on the oops concept and examples then you can go to
http://www.phpclasses.org/
Here you will find some incredible projects of php.

Since is conceptual and not language specific, look for any good OOP resource in any language and try and make it work in PHP.
Look at concepts like design patters, unit testing and domain driven development and you will expose yourself to a lot of OOP knowledge.
Start using libraries like Zend Framework and Doctrine PHP ORM in your PHP projects. They are object-oriented and by using them you will develop a greater understanding.
Also check out phpPatterns and the c2 wiki.
-Sam

You can try Codeacademy, it provides with tutorials in many languages : http://www.codecademy.com/fr/tracks/php

Related

Comparing php framework - by their unique features

I saw many many compares with php frameworks, but they are just rather general - OOP supported, MVC supported... there are really unique features which distinguish them. Symfony has flash variables, Zend has tons of classes for general purposes.
Anybody knows such compairing stuff?
Pick one you hear about, try it, and see what fits. Personally I've fallen for CodeIgniter, and just haven't looked into anything else as I haven't run into a limitation for my purposes.
Its really about picking the best tool for the job.
I'd say look into that table on Wikipedia that danp posted. I'd suggest doing some cursory research just by visiting the Wikipedia entries for a few of the top frameworks and pick one. The goal of a framework is to help the programmer to be more productive. If you have a good grasp of PHP and web programming in general, any of the frameworks will be a help.
If you are coming from a Rails background, I would suggest CakePHP or Lithium, since they share a tone of similarities with Rails. Hope this helps!
The problem with comparing unique features is that the unique features are mostly stuff you don't care about, otherwise it would already be implemented in the framework. I'd recommend you to go to forums, both people criticising it and raise it to the skies, see what their cases are and why their framework is a fit for them.
Don't just look for what a framework does, but what it does right.

What book should I use to learn Object Orietented PHP for web programming?

I am new to PHP but have good OOP idea. I am looking for a good PHP book the Guides to Develop Website in OOP Style.
I have purchased some books that all use Procedural approach to develop the website, or there are few book that show OOP chucks not a complete Webdevelopment Guide.
I need some book(source) that leeds me from Start 2 End of a website in OOP fashion.
The comments above touch-base on this, but I figured I would give a definite "answer" to your question.
The reason you have been having trouble finding a book that shows how to code PHP in an OOP fashion, is that it isn't capable of being programmed that way. At least not alone. PHP is a hybrid language that can do objects, but doesn't have to do objects.
Now, there are a LOT of PHP frameworks out there that help reinforce OOP standards in PHP. It is here that you may find books that are more OO-centric. But any book out there that claims to teach raw OOP PHP isn't worth reading.
If you learned OOP first, as more than a few people are doing today, you have a hard road ahead. You are going to need to unlearn what you have learned about Objects to be able to get PHP. It is a mix. It is a cobbled-together mass of everything in one giant pot.
This power comes at the sacrifice of formality and standards. OOP is about sacrifice of power for formality and standards.
Good luck.
EDIT
To expand on how PHP is not OO alone.
What I mean is that, as I said later in the answer, using a framework that helps enforce OOP principals can make PHP function like other OOP languages, or at least more closely like it.
I should also clarify my C++ not being OOP comment. C++ is in exactly the same boat as PHP, only it has been around long enough that OO has become a true standard and is well-practices throughout the industry at large. PHP doesn't have this. There are almost no strictly OO large-scale applications built in PHP. Working with strict OO standards in PHP on the high-end will grind your application to a hault.
Compare with real OOP languages/frameworks. Ruby, Smalltalk, so on. Or even almost-totally OO languages like Java and C#.
I would recommend this book:
Matt Zandstra - PHP Objects, Patterns and Practice, Third Edition
It is largely OOP focused, at the same times it sheds light on the shortcomings/limitations of OOP in PHP.
"Object-Oriented PHP" is a book: http://objectorientedphp.com/

Avoiding Bad PHP Coding

There is a lot of books and tutorials about php that are completely different from each other.
How can I choose the right way? Is the only way is test with xdebug or phpUnit or benchmark?
Have a look at the slides and the tools given at
Quality Assurance in PHP Projects
Disclaimer: I am not affiliated with Sebastian Bergmann or thePHP.cc - they just happen to be major influence on the code quality topic in the PHP world, which is why I suggest this link.
General Best Practices
As code quality/readability/maintainability cannot be "benchmarked", I suggest reading books about proper code structuring and best practices.
Maybe Code Complete book from Steve McConnell?
Consider using Suitable Patterns and Frameworks
It's also worth mentioning the use of a well defined pattern like MVC and build your project with some Framework like Zend, as this will encourage you to put each piece of code where it belongs.
xdebug is a very powerful tool and can help you a lot.
You will be able to see in your development server (and not an ideal server) what is happening with your code!
If you like to improve your php code here are several advices:
do not use procedural programming, use oo
use some framework like kohana
use patterns every time
read some books about java oo programming (good book: beginning java objects 2 edition)
Aldo it is different language, java teaches about good oo code and patterns.
do not use functions with cyclomatic complexity>20
Most programmers use complex hierarchical associative array. They are hard to maintaine. avoid using complex structure of associatve array as DTO, try using classes.
use coning standards.
test driven development, unit tests. If your code can be tested with unit tests you are one step towards good code. Continuous integration is always welcome, but not always suitable in php, depending on the code and libraries you are uning.
use mvc, layers in you architecture
there are a lot more thinks, but keep reading and improve all the time
Regards
Get experienced. Once you have changed a switch statement with instanceof's a couple of times, you see the advantages of polymorphism.
Keep thinking critical of your own code. Keep thinking about how you solve things and be open to other ways.
Read code. Unfortunately, most PHP code is not a good example on how to write code, but you will learn something from it nevertheless.
Read a book. A book is often more in-depth and detailed than any article on the interwebs.
Download a well known open source project or framework like Zend. Then read through some of the code to see how they approach common tasks, and the general structure they use.

How to do OOP Based Web Design in PHP?

How to do OOP Based Web Design in PHP?
May be you could link to me a post containing a tutorial or reference to Design Web in OOP Fashion?
The easiest way is to get a framework to help you with it. By far the most common pattern is Model-View-Controller, or MVC.
Try
These
Questions
The last one has a good link to the PHP manual guide to OOP.
if you are beginner then I will suggest to read The essentials of Object Oriented PHP.
You will get Clear concept of major OOP concepts with example.
There are exercise section after each chapter and end of the book with solution too.
Also check this serious of Videos PHP OOP Tutorials

Writing Clean and Efficient PHP Code

I have been looking around online and I cant seem to find an article on this that isn't totally outdated. Does anyone have any good articles that give some good advice? What I have read so far is good, and a bit helpful, but I want to have modern code examples, not ones from 2002.
I have coded an extensive PHP/MySQL program and I am trying to make it better now, any suggestions?
EDIT:
People are suggesting frameworks, and I appreciate it but I am looking for coding tips for raw PHP Coding. The whole application is already done and it would be very lengthy to recode the entire thing in a framework.
I will be checking those out for future projects though. Does anyone know or have any tips for Writing Clean and Efficient PHP Code?
Use Smarty
Write to patterns as much as possible.
Edit for the Question Edit
Clean and efficient PHP isn't much different than any other language. Practice good Object oriented principles. Focus on Encapsulation, Separation, and Polymorphism. Refactor often, and Utilize design patterns as much as possible.
There are many sites that focus on these principles. Some use Java, C++, etc. to demonstrate the principles, but it shouldn't be too difficult to convert them over to php.
I'd take a look at the Zend Framework. It is a great framework that encourages PHP developers to use better practices like MVC, OOP etc. If you are not used to this paradigm, I have to say that it will seem daunting at first, but if want to continue with your PHP development I'd suggest downloading it, and start the "Getting Started" tutorial.
There are other frameworks, CMS tools that you can download, but the Zend framework offers are very raw approach to building great PHP applications.
Acorn
PHP Classes helped me a lot (when I was coding PHP). Reading better code usually helps improve my own.
If you haven't already, I suggest making your PHP code object-oriented. It promotes reuse and makes code a lot more readable. Here's a link to show how useful it can be for reducing lines of code etc.
Use CakePHP. It's an excellent MVC framework. Steep learning curve, especially if you've not used MVC before, but the tradeoff is certainly worth it.
Like folks said, frameworks are the way to organize your code best. Many support Model/View/Controller; many are object-oriented already. Try to stick with a PHP5-specific framework (the code will be much cleaner; PHP4 did not support OOP fully). Try to go with the simplest possible templating engine. One PHP5 framework I like that hasn't been recommended yet is called QCubed.
One thing in your post worried me, though - you're saying that you already have the application written, and are now trying to make it "better". If that's the case, trying to switch over to a framework now may be a HUGE (literally huge) task. If this is an application you expect to be in production for 3-5 years, I'd consider taking a plunge; I'd then try to take little pieces of the application and integrate them into that framework environment. Doing it wholesale is a recipe for pain.
For clean PHP code you can use PHP CodeSniffer (search for CodeSniffer on http://pear.php.net since direct links don't work) it's an automatic code style checker. You can define your own codestyle rules and then check the code.
You can even script it, so your code gets checked before SVN commit.

Categories