tags:

views:

648

answers:

7

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?

+8  A: 

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.

Matthew Vines
+1  A: 

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.

AlbertoPL
+2  A: 

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

Acorn
+1  A: 

PHP Classes helped me a lot (when I was coding PHP). Reading better code usually helps improve my own.

Luca Matteis
A: 

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.

mgroves
+1  A: 

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.

Alex
that is precisely why I am looking for PHP coding techniques not frameworks that everyone is suggesting.
Chris B.
+1  A: 

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.

Vexatus
404 document not found.
Joey Robert
I've changed the link, maybe they check the referer?
Vexatus