ClassicPHP, a Project Agnostic PHP Library

ClassicPHP is a new library in development meant to make your life easier as a PHP web developer. It takes the most necessary tasks for any project, and allows you to do them by calling a method, rather than writing similar code in those projects. That’s ClassicPHP in a nutshell.

What ClassicPHP Does

Unfortunately many projects use hodgepodge code for basic tasks, like connecting to the database. In these projects, the code is very specific to that project, such as querying a specific table for records that have a specific value in a specific field.

function get_users_after_date($date) {

    $pdo = new PDO();

    $pdo->query("SELECT user_login FROM wp_users WHERE user_registered > '$date'");
}

Other projects use a class to make basic tasks, such as querying the database, easier to process and re-implement for multiple use cases in that project. While this is much better overall, unfortunately the developer often still ends up with different classes of these types in multiple projects. This was my experience while developing multiple WordPress plugins. Each plugin needed a very similar, yet slightly distinct, class to handle connections to the database. The ClassicPHP library’s main goal is to help eliminate this code duplication, focusing mainly on simplifying tasks which are common to most PHP projects.

What You Can Do with ClassicPHP

Here is a break-down of the functionality offered by the library at the moment.

  • MYSQLPDO-Family of Classes — Send a database query to the database using a single method, simplifying every database connection you need for your projects. For example, your can:
    • get database data using the MYSQLPDO_Read::select_query() method,
    • add a new record to the database using MYSQLPDO_Write::insert_into_query(),
    • or update a table definition using MYSQLPDO_Manage::alter_table_query().
  • ErrorHandling Class — Offers some basic error-handling features, such as throw_error(), so you can better control the information and formatting when an error is thrown anywhere in your code, without writing your own class or functions for this.
  • Test Class — Provides some testing methods that might be useful while testing or debugging your code. The unit_test() method allows you to test functions or methods using specific input and expected output, when searching for possible bugs. The benchmark_execution() method allows you to test to see if one method is relatively faster than another.

Check out ClassicPHP on GitHub.

Why is ClassicPHP Unique and Worth Using?

One of the key features of this library, and the main reason for beginning development on it, is that it’s project agnostic. Frameworks require an investment in the ideas and functionality behind the framework. So while Laravel has great functionality for debugging code and connecting to the database, it requires complete buy-in, and that can sometimes be a problem. Not so with ClassicPHP. As I am a WordPress developer at Saffire Grill Co., I don’t want to subject my company to a framework like Laravel which, while it has plenty of power, requires a complete change to the way WordPress works behind the scenes. That, to me, seems like overkill, just so I can develop a handful of plugins faster. Hence, this library, which does the repetitive work for us, while also improving consistency across all of my work projects.

State of the Library Now

At the moment this project is version 0.2.1, so this is still an early development. However, I plan to use this library in my own projects, so that will provide the motivation to continue to improve and expand it. The project is licensed under the GPL 3.0, so feel free to use and fork it as you see fit. See the complete project on GitHub here.

Leave a Reply

Your email address will not be published. Required fields are marked *