Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 335
Chris Bier Avatar asked Jun 24 '09 15:06

Chris Bier


People also ask

What is clean code PHP?

Clean Code PHP (jupeter/clean-code-php), is a guide based on the book Clean Code: A Handbook of Agile Software Craftmanship, a classic programming book about writing maintainable code by Uncle Bob Martin. The clean-code-php guide is inspired by a JavaScript adaptation, clean-code-javascript with PHP-specific features.


3 Answers

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.

like image 113
Matthew Vines Avatar answered Nov 15 '22 18:11

Matthew Vines


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

like image 33
Acorn Avatar answered Nov 15 '22 18:11

Acorn


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

like image 2
Luca Matteis Avatar answered Nov 15 '22 16:11

Luca Matteis