Building a PHP Foundation

As of writing this article, I have been a PHP programmer for nearly 8 years. Through my experience, I have learned a little about how to be successful PHP developer. In this article, I will share about what I have found to be crucial for any PHP developer: maintaing a library of PHP code that you can reuse in different projects.
It is important for PHP developers, and any other deveopers for that matter, to gather scripts, classes, and functions that they can reuse later. It saves so much time down the road when you can reuse a script that you have used in other websites. For example, there have been numerous times when I have wanted to programmatically determine what extension a file name has. The high demand for such a function among my projects led me to write up a nice file extension function, which I saved into my personal library. Now, any time I want to get the file extension for a file, I can just copy and paste that code into my new project. By the way, the file extension script is uploaded to PHP Share for anyone to use!
Other times, I store more than just functions in my libray. Often, I store entire PHP classes, which I then can incorporate into my projects via a require_once() or include() statement. I have classes that get information about the current page URL, classes that perform MySQL functions easily, classes that deal with cookies, classes that generate CAPTCHAs, classes that compress stylesheets, classes that handle email, classes that output copyright lines, classes that provide an interface for Facebook Connect, classes that handle rating systems, classes with utility functions, and classes that handle user input—to name a few.
The point I want to make is that once I have these different functions and classes saved in a personal library, developing a new website becomes easier and easier. However, I will caution you about one thing. There is a caveat involving in having classes upon classes that you just implement into your websites. That caveat is that, if you are not careful, you can include more code than you need in websites. For example, I might have a string utility class that makes it easy to perform certain operations on strings. I might use that class extensively for one website, but only need one function for another website. That introduces a lot of "code bloat," which will slow down my website and make it harder to maintain. It is for that reason that I often avoid PHP frameworks, whose goal tends to be to increase productivity. When I have my own personal PHP library of functions, it is a lot easier to prevent code bloat because I know what everything does and what functionality is offered.
I want to wrap up the article by discussing how PHP Share can play a role in your building of a PHP foundation. PHP Share lets you upload your library of commonly used PHP functions and classes so that you can reference them later. Instead of saving commonly used code locally on your computer, why not take the extra minute to just upload them to PHP share instead. If you do, then you will be able to access your code from anywhere, search for classes and functions based on their tags, and help out others by offering them useful code. You can add anyone else's code to your "personal library" by adding PHP scripts to your favorites. It's that simple, and I wish you the best of luck in building your own personal library.




Not a member? Register today and receive the many free benefits of being a member!