views:

227

answers:

7

I've been 'hobby programming' in PHP for around a year now in my spare time, starting off with the "PHP and MySQL for Dummies" book and working through "Beginning PHP and MySQL from Novice to Professional". As I'm sure you can imagine, my knowledge is fairly limited and I'm probably already knee-deep in bad habits!

I've been working on a 'dummy application' for the past 6 months or so, and feel that I'm making reasonably good progress, however I haven't been exposed to any 'enterprise level' PHP code yet and I wondered if there are any sources where I could find some examples of 'good practice'?

+2  A: 

I imagine most answers to your question will point you to good books, perhaps not even specific to PHP, like "Head First Design Patterns," or even online tutorials, but my absolute favorite way to learn new styles of PHP is by looking at the source code to big open-source PHP projects. Take a look at how CakePHP or Symfony is written. Compare that to how something like Zen Cart (as an example of what not to do). The widely adopted and active open-source projects generally evolve to include better, highly readable, modular code, that you can attempt to mimic in your own projects.

stereointeractive.com
+2  A: 

I'd say the best way to learn is to practice ; and, as you don't want to learn from some crappy code/application, I'd say learn with one of the big frameworks, like symfony or Zend Framework

Follow their coding standard, do what's said in their documentation, read their source-code :

  • You will learn using a well-known framework, which is great for you, and will look great on your resume too
  • You will learn best practices / design patterns that those frameworks use (and allow you to use)
  • You will have lots of great source-code to look at (and, sometimes, looking at the source of the framework you're using is the best way to learn / understand what it's doing and how -- or why the **** something isn't working the way you'd expect ^^ )
Pascal MARTIN
+2  A: 

I have to recommend learning the Zend Framework. It's the only enterprise PHP framework in my opinion. I also suggest read Rob Allen's book Zend Framework In Action. It'll get you up and running quickly. The manual for Zend Framework is also very comprehensive and full of great samples, and all around good practice.

hobodave
+1  A: 

Here are some links to actually answer your question -
Nettuts
PHPFreaks - good Object Oriented Programming series
SitePoint PHP

I personally like the O'rielly books the best for Technical books, although I would wager that most of what you need you could find online (Not always - and there is something to be said of a good book :) Apress makes some good techical books too. Be warned however, good technical books aren't cheap. Around $40 starting out.

To be honest, most of the web sites I have bookmarked I have found over time, and the same will be for you. You will find a few that you go to time and time again for advice and help.

I would suggest a few things. One, as people have said already, just practice. You learn the best and fastest when you practice, and practice often. Second, when you practice, don't take the easy route. Some things may be easy just because they are, but don't do it when a better route is available, even if it is a little beyond you. We learn more when we are stretched than when we aren't. Lastly, if you haven't starting looking at Object Oriented Programming - do. This is definitely involved in enterprise level coding. In fact OOP forms the basis of most programming today as well as most modern design patterns.

Learn how to program in general and at the same time how to program in PHP. In general I am talking about writing readable code, making proper use of comments, project organization, problem solving, and good design patterns. These are practices that are not language specific. Hence why many say once you have learned to program in one language, you can program in most any language - it's just learning new syntax. Once you have a good solid foundation, then I suggest you start looking at some good frameworks. If you just start poking around without a good base, you'll get lost quick and won't learn as much. Besides, there is a difference between learning how to use a framework and looking at the code of a framework and seeing how it works. Just copying and pasting code is good and you can learn, but can hurt you if you don't understand why they are doing it their way.

Robert DeBoer
A: 

When I first starting getting into PHP heavily and wanted to learn how to write better code I read the Zend Framework Coding Standard for PHP. Some of it really only applies to the Zend Framework but much of it can easily be adapted for any PHP project.

There are somethings like the brace style and the tabs vs spaces indenting that would depend on what you like. The key with these is to be consistent.

MitMaro
A: 

Within the Zend Developer Zone you will find a lot good explained samples.

PHP 101 for beginners

Bernd Ott
+1  A: 

Use a framework. You can read books and examples of good code too, but the best way to learn is practice. Frameworks (like the Zend Framework, Symfony, and others) emphasize the importance of writing good code and good documentation. Perhaps more importantly, the communities that surround them also tend to emphasize good code and good documentation, which helps isolate you from bad practice that (imho) is prevalent in the mainstream PHP community.

Matt