Becoming a Kick-ass PHP ninja

Who is this for?

You’ve been developing web applications using PHP for a couple months now and are finding it very enjoyable. Although you feel that you’re doing quite good, you’re not sure whether its the end. Besides, the following questions wonder you often:

  • Where to go from here
  • What new things to learn
  • How to become a Kick-ass PHP Ninja

If that’s the scenario, then this post if for YOU.


A few days back, I read a number of blog posts where people have highlighted the shortcomings they see in newbie developers. Some of them have gone further to narrow down the focus on PHP developers only (as PHP’s nature sometimes allow developers to avoid standards). They did a great job by listing the shortcomings, but their posts missed clear way forwards (these can be inferred though). A number of readers also commented on the posts with their insight as well. So I was thinking how about compiling all these in an easy to follow list? Hence this post.

Btw, due to the volume, I’ve mostly touched the points here and provided few useful resource links for further study. I do have plan to elaborate a few of them in coming posts, with each point becoming a single post. Let me know which ones you’ll prefer most, by entering the poll at the bottom of the post.

Part A : Technical Way Forward

In the first part, let’s shed some light on how you can move forward with your technical abilities.

1. Start using version control

Version control is like a big UNDO button for your coding. You can go back to your previous code revisions and can compare/rollback to specific code areas anytime you see necessary. It will keep track of all your changes and will empower you to track your development changes across your work/team. Also, in a distributed development team, version control helps prevent overwriting of code by team members and keeps all the members code up to date.

Subversion (SVN) is one of the most popular open source version control system. If you’re on windows platform, you can try TortoiseSVN, a client for SVN.

2. Write code in OOP way

If you haven’t already, it’s high time you started writing code in Object Oriented Programming (OOP) way. You may ask why? Well, OOP forces you to write code that is maintainable in nature. If properly followed, OOP code become a lot efficient than procedural code. Also, it allows you to re-use code across your project and/or multiple projects.

If you’re not convinced, have a look at these excellent resources for further study.

3. Adhere to a coding standard

Coding standards allow you to write code in a way which is easily understood by other people. When you adhere to a coding standard used by may others, you actually convey a message that you’re serious in writing code that people will be able to “get” and maintain. Keeping abbreviation type variable names, applying multiple indention types, writing meaningless function names etc will work for you in short term, maybe in personal projects. But when you move to a larger group with a number of developers, you ought to follow a standard so that everybody working with you can get along with your parts.

The following standards are most widely used among PHP developers around the globe:

Although you can define a standard for your team/company, it’s always better to have close relation with what the industry follows. In my company, Right Brain Solution Ltd, we follow a slightly modified version of Zend Framework Coding Standards. You can get that one here.

4. Document your code

Documentation is a virtue of great developers – don’t get me wrong, I’m talking about code documentation, not writing user manuals 🙂 Well documented code prevents other team members from reading each line of your code and understand them by heart. Rather, it tells them exactly what they need to know – purpose of the code, what it requires as input, what it will deliver as output, etc. If you take a look at the above mentioned coding standards, you’ll discover that most of them even specified standard for documentation as well, which is phpDocumentor. It’s the most used standard for PHP code documentation and is widely recognized.

5. Use a good framework

Frameworks give you good structure and helps you build web applications in a fast way, with confidence. Most of today’s popular PHP frameworks (Zend Framework, CodeIgniter, CakePHP, Symfony, Kohana etc) follow the Model-View-Controller (MVC) pattern, which itself is a strong advocate of good practice.

Besides structure, frameworks force you to write code in a structured way. Some of them will also require writing the code in OOP – whose benefit we already discussed above. And frameworks usually come with a number of helpful libraries and helpers, to make your life easy as a web developer.

Josh sharp discusses this in details here and later posts a follow-up here. Both are good reads.

6. Re-use code/libraries

One of the most common advice programmers get is: “Don’t re-invent the wheel”. Well, what’s the point here? It actually means that you should not spend much time on solving a problem that has already been solved, in efficient way, by others. Rather solving it out yourself, you can “google” it and see how others have done it. It will not only save your valuable time, but also will ensure stable code (assuming that people usually post things on web after doing a number of testing and user of the codes usually help iron-out any issues, etc).

However, keep an eye on your target use/objective. If there is not enough good solutions that solves your problem, go ahead and solve yourself. Make it good and give it back to the community so that others facing that problem won’t need to spent the time you’ve spent. The whole open source model runs on this give-give way, so be a part of it.

7. Test your code the right way

In order to make confidence out of your code, you’ll need to test your code the right way. Although you might be used to testing your application using debug messages and browser refreshes, in a real world scenario these won’t work. You’ll need to write unit tests which can do automated testing of your code. The power lies in that you can run these tests almost anytime and can check if anything is broken after each new change.

PHPUnit and SimpleTest are the two most widely used Unit testing suite for PHP. You should also have a look on Test Driven Development (TDD), which is the way of greatly enhancing your chance of deploying application with least bugs.

Part B : Personal Way Forward

Now, even if you’ve improved yourself on the above mentioned points, you’ll still need to work on your personal matters to move forward. Here goes those points.

8. Be Agile

You need to be an agile developer if you want to move forward in your career. What does it mean to be agile? Agility is more of an attitude than a skill set. The common characteristics of agile developers are:

  • They’re open minded and therefore willing to learn new techniques
  • They’re responsible and therefore willing to seek the help of the right person(s) for the task at hand
  • They’re willing to work closely with others, pair programming or working in small teams as appropriate
  • They’re willing to work iteratively and incrementally

Further resources: Agile Software Development, The Agile Manifesto.

9. Keep yourself updated

No matter what, keep yourself updated on whats going on in your field (in this case PHP). Subscribe to the RSS of great PHP blogs and skim over them on a regular basis. Dig into the topics that interest you most and see the author’s point. Also, keep a habit of trying new technologies every now & then. It gives you an edge over others and when any discussion goes about it, you can help others understand as well as make your points.

Btw, if you don’t have a clue where to find good blogs, have a look at here, here and here.

10. Start community involvement

Remember I told above to give your work back to the community ? How to do that ? Start a blog of your own and start writing posts there every now & then. Yes, I know you’d say “Who’s going to read my blog anyway?”, but if you share your experience, someday, somebody will find it useful. And if you can share things that others haven’t done, you’ll slowly see visitors coming on your blog increasing way.

Besides blog, try to participate in tech forums and communities. Help people out in the areas you excel and at the time of your need, other people will be happy to help you out as well. These communities are also great place to learn about many unusual matters, see how situation changes from person to person, place to place, etc. You’ll also be able to make great friends who might come handy later in your life.

Another great way of community involvement is to contributing to open source projects. Share some of your valuable time for an open source project and it may come handy for a huge number of people. Your work might solve the problem of somebody like you. If needed, initiate an open source project yourself and invite others to work on your vision.

11. Use a good IDE

With due respect to Dreamweaver, step forward and use an IDE made for PHP. You’ll notice the difference in a few days when you’ll see that your productivity has increased in great ways. These IDEs provide great number of useful features including but not limited to: syntax highlighting, auto completion, code suggestions, code snippets, contextual help, code templates, debugging, profiling, etc.

The following IDEs mostly have the similar feature set and can boost your productivity in great ways:

Personally I use NuSphere PhpED 5.2 and I love it in every way. They’ve provided me with a complementary license and I am grateful to them for that. If you’re planning to buy it, let me know and I might find you a discount.

12. Be communicative

In your team/company, try to be as communicative as possible. It reduces a lot of confusions, makes you close to other devs so that you understand them, portrays you as a good person in front of management and overall, helps you enjoy your work. When you’re working together with others, make them feel that you’re there and ready to give whatever it takes. Create a personal brand of yourself.

What’s next?

Phew! It’s quite a good amount of writing in a while 🙂 I’ve tried to cover most of the items I found to be important. However, there might be some points I’ve overlooked so feel free to post them in the comments. If this helps any one of the developers I intend it for, then I’ll take that the effort is successful.

Thanks everybody, Happy Eid Mubarak to you!

[poll id=”3″]

68 thoughts on “Becoming a Kick-ass PHP ninja

  1. all the points are very important. most of us are well in php but maximum time we fail to update ourself becz of proper guidance.

    thanks for this informative post.

  2. With due respect to PHP and this blog but after reading all this suggestions why no better use Java and be done, It have all what you suggest but much better than PHP, PHP has been a kitchen sink since the beginning so it drives to people to make a mess on their code, And also Dynamic languages have similar problems as statically languages when the code grow.

    1.Version control: All programming languages should use it even I use it for my excel docs.
    2.OOP: Java it drives you to do proper OOP.
    3.Coding Standards and Patterns: Java have it too in a higher degree.
    4.Document your code: Java have thousands of good tools for it.
    5,6,7. Java have gazillions of neat frameworks to choose, use JUnit for testing, Java is a proper OOP you can reuse your objects and components check Spring, Guice, OpenEJB those can help you to do it much better.

    8,9,10.Same in Java as PHP.

    11. Good IDE: Java have awesome IDEs with awesome refactoring tools and much more, Eclipse, Netbeans, IntelliJ, Borland JBuilder, MyEclipse.

    12.Java same as PHP.

  3. @Chekke: In my opinion, Java and PHP both are excellent languages and they have their own place where they excel. Although Java can be used in almost all scenarios, for web based solutions PHP can be more handy than Java. It allows developing and deploying quality web application in record time. And with the latest additions to the PHP language, these applications can be robust and secure.

    I suggest you keep an eye on the latest trend in PHP, you’ll see that it’s quite a mature language right now. I’ve seen people using both PHP and Java, which they use for specific need.

    Thanks for your comment though 🙂

  4. A guide for newbie PHP developers to become a kick-ass PHP ninja by upgrading themselves through a number of technical and personal improvements.

  5. The reasons for coding OOP could be more elaborated. OOP by itself doesn’t force you to write more maintainable code – when I started writing OOP my classes where just containers for static methods which I used just like I used functions. It wasn’t until I started using the Zend Framework that I really grokked the benefits of OOP and how to use it effectively.

  6. @Emran Hasan, Thank you for your message at DZone, I will take a look more close to PHP.

    @Frank, Im not interested in the template that is the easy part, Im interested in the model or controller code or the code behind.

    The templates you could use Freemarker for a MVC framework or Facelets for JSF, it is similar as PHP templates. Take a look at Freemarker or Facelets are just xhtml templates. JSF it is a spec for web component based frameworks, It is not a template language, JSP it is the template but is not the best practice to use with JSF and I’m agree JSP sucks, thats why there are other alternatives and much better.

    But also I’m agree with Emran Hasan that PHP can be helpful in some situations and Java in others, I’m just suggesting that if you care a lot about OOP or best practice and patterns Java it is better option IMHO.

  7. Very helpful post. I will definitely be adopting some of your points, although maybe not all in one go.

    Think that phpDocumentor will be first on the list, as I already pretty much follow the coding standards.

  8. Very helpful guidelines for the developers. These guidelines are very standard, unique and latest. I am sure so many developers get this direction from here. Thanks a lot for sharing these.

  9. I also love vim, but as a great text editing tool. It’s not an Integrated Development Environment (IDE) in the true sense. An app needs to have loads of bells and whistles to be considered to be an IDE 🙂

    Thanks for your comments!

  10. Very good & helpful article for the potential newbies who want to do well.
    Now we can just forward the link of this post to the newbies instead of giving them a long lecture :D. Good job.

  11. Hello, good post. There never seems to be enough time for me to do OOP 🙂
    I am a micro-manager with code and I understand by building, that’s why I like to re-invent the wheel, make sure when I do I take a good look at the wheel from security, flexibility.
    I love the thought process of event driven 🙂 It just feels to intuitive and the web really is 100% event driven, it’s a disconnected system and you can only rely on one event at a time.
    I just don’t have that magical OOP feeling for the web.
    When I develop outside the web I do C and C++, and it’s a different world the communication is different. And While I develop AJAX JSON stuff in web, I always start with the assumption that the user and session is completely disconnected and never treat it like a real app.
    I spent the time to write a very extensive and well rounded class for mysql. Then in everyday use, it just didn’t feel right, I can’t help but thinking hmm I miss my normal functions 🙂 I miss my quick n dirty mysql_add_my_row($table,$fields,$vars). What am I missing out with on OOP? When I program OOP half of developers whine saying what is this, then the other half whine hey we use cake, you use zend.
    I follow the rest of the practices to the point, svn, inline documentation, code format, etc. I am just not an OOP guy, can someone help sell me on the religion of OOP?
    Thanks for the help! 🙂

  12. Using a framework doesn’t make you a ninja. PHP is not really designed for the use of big frameworks and using one can actually slow your code down. See Rasmus himself telling us why:
    This is different from writing using software patterns. Writing in software patterns can help.

    Also, being agile as you describe it is different from Agile Development, which is a very specific form of development methodology. Agile Development suits some projects and not others whereas your definition of having a dynamic personality is useful always.

    Also, OOP is a huge overhead for many of the simple functions you need to perform with scripting. Chances are, if you need to make something huge, scalable and quick then you’re going to write the guts in your favourite compiled language such as Java/.NET/C/C++ etc. PHP is not designed for that and so falls down on fast backend processes.

  13. Using a framework doesn't make you a ninja. PHP is not really designed for the use of big frameworks and using one can actually slow your code down. See Rasmus himself telling us why:
    This is different from writing using software patterns. Writing in software patterns can help.

    Also, being agile as you describe it is different from Agile Development, which is a very specific form of development methodology. Agile Development suits some projects and not others whereas your definition of having a dynamic personality is useful always.

    Also, OOP is a huge overhead for many of the simple functions you need to perform with scripting. Chances are, if you need to make something huge, scalable and quick then you're going to write the guts in your favourite compiled language such as Java/.NET/C/C++ etc. PHP is not designed for that and so falls down on fast backend processes.

  14. “Write code in OOP way” – this doesn’t really make sense.

    PHP is a scripting language – don’t forget that. Using objects and classes is important, but not vital to proper coding in PHP. Writing all your code within classes like many frameworks out there do creates a lot of overhead that isn’t necessary when developing a website, and causes developers a lot of headaches just trying to get a simple website setup with a few dynamic sections.

    OOP is a practice, and in PHP its just an option. Unlike other languages such as Java which are completely object based languages. Utilizing PHP’s variable and object scope is much more important in my opinion.

    Things to use objects for: modular information (such as a user entry, or a database wrapper)
    Things NOT to use objects for: normal page procedure (Zend framework does this, and although this is a robust framework it is silly to waste time programming this way when PHP programming is meant to be a faster alternative than other languages – you might as well just use Java to program if you want to do it that way, it will be faster)

  15. Yes, sometimes re-inventing wheel gives you the chance of learning the rope closely. Regarding your mysql class, doesn’t it help your life a bit easier by doing stuffs for you? I’d imagine my class would have some functions like thins:

    – read(1);
    – findAll ( “status = ‘published'” );
    – update ($post, $id);

    to speed up my development time. Back in my head i know the generated queries are safe, structured and does their work pretty good. Just my thoughts 🙂

  16. Yes, I read Rasmus’s post earlier and somewhat agree with him. But I’ve also read one of his interviews in Sitepoint where he mentioned CodeIgniter to be a framework that actually looks like a framework to him and has some good use.

    In my personal opinion, some frameworks just try too hard to bloat everything and loses the main focus. For me, the objective of a good framework has to be providing structure to projects and provide a number of useful functionality like db abstraction, security, caching, profiling, url mapping, helpers, etc etc.

    Regarding PHP’s speed compared to other compiled language, it’s a plain truth. A scripting language can not be as fast as the compiled ones. However, it can more or less handle the pressure of web – at least upto a few millions – if the app is developed properly and optimized for large traffic.

    Thanks for your comment 🙂

  17. I personally do not enjoy Dreamweaver. Snippits stop a developer from going through his or her code, and can pose a threat. Code templates should be avoided. Again, an IDE should not be holding your hand through the process. Rather, they should simply be a utility with little interference. And auto completion seems nice at first, but when you use Prototype or Mootools they do not indent properly. And when you are using strings they attempt to end a tag when you don’t want it to. So, again, this feature gets in the way of freedom to code, and hinders the thought and logical process.

    I tend to prefer Scite. Though, with this editor, you can only have 10 documents open which is a pain. And it is missing two very good features of Dreamweaver: Entire site search / replace, and suggestions (which are very handy, specifically with CSS).

  18. My biggest issue is all the additional stuff in a framework. For example, Form helpers. They just tweak me off something fierce. I do not believe that they are necessary, and are in fact, an unneccessary overhead. I have been proramming web apps for many years, and I don’t understand why people say that using a form help is so much better than just writing the form out yourself? I know all the lines of html code necessary to create a form. Why should I learn a whole set of functions that do what I already know how to do?

    Someone said to me that it keeps the form separate from the PHP code. If you use an MVC framework, you can still put the html code for the form in the view.

    I have used my own type of framework, and my applications have been very quick and snappy. They definitely don’t use separate functions and commands listed in arrays to create an input box!?!?!? Why, it’s not necessary! I will admit that I may use a function that starts the form an ends the form, but not to populate the contents of a form.

  19. This is an excellent post.

    Points well covered, and the “further reading material” in each point makes this post very valuable.
    Thanks for sharing this.

  20. While only for OSX, I’ve found that Coda is an excellent IDE and the one I’ve settled on after trying most everything else for Windows, Linux and OSX. Coda has all the features I need and none of the extra bloat I don’t. If you’re a Mac user I strongly encourage giving it a try.

  21. While only for OSX, I've found that Coda is an excellent IDE and the one I've settled on after trying most everything else for Windows, Linux and OSX. Coda has all the features I need and none of the extra bloat I don't. If you're a Mac user I strongly encourage giving it a try.

  22. “Write code in OOP way” – What did you mean by this bro?

    OOP is not a way of coding. It’s intended to match real world modeling in programming. When you think of OOP then you have to take every entity as object. I think you still really have some shortage of some software engineering knowledge. Though this article could be helpful but finally realized that you are not a true IT Professional. May be diverted form other field to this field. Still lots to learn buddy.

  23. Thanks. It is very useful article. My favourite titles are:
    Write code in OOP way,
    Use a good IDE,
    Test your code the right way,
    Re-use code/libraries

  24. Nice post. It’s a continuous process to follow the system.I think this system is always true, not only for php but also for any other language/project work. Just carefully we follow the process when we do our jobs, we must improve ourselves. But one most important part of learning new technologies/languages/problem solving approach/anything is the last part, “B COMMUNICATIVE”. It ‘ll always improve team work as well as our running project.

  25. Excellent article. I tried a framework and found it hard to use because i had to program the way they did. It was expendable however I found it limiting. The other concern I have is it might cause my code to become open source. While I like giving to the community I do not want an application I work on for 300 hours to be vulnerable to becoming open source.

    Learning how to re-use code is probably one of the biggest thing a programmer can do for himself/herself.

    Angain great article!

  26. Thanks for your reply. I would not argue about the sentence, but tell me one thing: didn’t you understand what I wanted to mean? If yes, then I think my target is achieved. And remember, this article is meant for all the newbie PHP developers out there – not only for those who have a software engineering background.

    And don’t know what the word “diverted” means here, but I’ve been programming since college. And if you think I’m not a “True IT Professional” that’s fine with me as I don’t mind about people saying things that they don’t know about – its their discredit, not mine 🙂

    Oh btw, what is your blog address where I can find good posts on software engineering?

Comments are closed.