8805534617_3bdbbb0f31_b

Before I started working with the  PHP programming language, I had little to no respect for it. This was basically due to a mindset I was made to adopt by my immediate environment and within the work environment. PHP has always been regarded to as the shittiest programming language out there but I put this question to you: What makes it shitty? What can other programming languages do that PHP can’t do?

I asked a couple of people this question and they had no reason why they thought PHP is shitty. Those who had something to say about PHP being shitty had only one line… SHITTY CODEBASE. To this I say they could be right but they are also very wrong, shitty code can be written with ANY programming language.

What makes other programming languages seemingly better than PHP is the rules and standards by which they are governed and the strict employment of OOP in programming and thanks to a group of PHP developers, known as the PHP League (The League of Extraordinary Packages), standards of using PHP by programmers to build awesome applications, i.e. PSRs (PHP Standard Recommendations), came into existence.

What makes PHP AWESOME?

1. PHP is probably the easiest programming language you can ever have to pick up to learn.

2. It gives complete freedom to the programmer to program his/her style and make it work for him/her.

3. Procedural PHP, which seems like a flaw in PHP, is in fact another thing that makes PHP a lot easier to use. Imagine you are designing a web application to strictly market a product or an establishment. All that is needed, basically, is a lot of HTML and CSS but perhaps you are to include a contact-us form to send a mail to the establishment, you do not need to complicate the app and “OOPize” it. PHP allows you write procedural code to execute this as fast as possible. OOP is a very important concept in programming but when creating very tiny and small projects, OOP might be a bit too much.

4. Do not let us go into talking about the platforms online that currently run on PHP.

5. As a PHP developer, you get to use dollars every time which means PHP developers got a lot of dough. “Yea, we rich as hell”.

Screen-Shot-2015-10-17-at-1.56.32-PM

GETTING STARTED WITH PHP

There are six basic areas of coverage to learning any programming language for the first time. Understanding how these six areas are implemented within any programming language is the best way to get you started learning it. Progressively in the order as listed below:

  1.  Variables and Datatypes
  2.  Data structure (Arrays, List, Hashtables, Stack, Queues, Dictionaries, Maps)
  3.  Functions/Methods (Modular programming)
  4.  OOP implementation
  5.  Files and Databases (persistence (session, cache and cookies) and storage)
  6.  Testing

NB: PHP offers ALL of the above listed.

PHP possesses the general control structures and decision statements e.g. if statement, for statement, while statement, foreach statement, do-while statement, etc. Creating a variable in PHP is just as easy as making dollars. All you have to do is add a dollar sign before your variable name and voila, you’ve created a variable.

PHP data structures are based on arrays, so if you can understand fully how arrays are implemented, manipulated and used in PHP, using data structures in PHP would be as easy as breathing or eating.

Screen-Shot-2015-10-17-at-1.59.34-PM

PHP has all the OOP functionalities as well, so it is possible to build a well architectured OOP application using PHP.

PHP DATA OBJECT Class (PDO)

Screen-Shot-2015-10-17-at-2.02.13-PM

Another major awesome feature PHP offers is the PDO class. A lot of people have assumed by default that PHP only works well and adapts easily with  MySQL probably because every tutorial out there is branded “PHP & MYSQL” but I am happy to inform you that you are indeed very incorrect. PHP can easily be used with all sorts of database types. Postgres, MicrosoftSQL, Oracle, SQLite and even MongoDB.

The PDO class is what makes database connection so super awesome and easy in PHP. It is an abstraction layer for connections to SQL databases, so you can use the same code to work with MySQL, PostgreSQL or any SQL database. PDO is extremely easy to understand and implement.

PHP PACKAGE MANAGER (Composer)

Screen-Shot-2015-10-17-at-2.02.42-PM

Yup! PHP has its very own Package Manager, just like JavaScript’s Node Package Manager (npm) and Python’s Package Manager(pip), which is composer. All PHP packages are hosted in a repository called Packagist. Packagist is the default Composer package repository. To add any package managed on packagist to your application, all you have to do is download composer, run a composer init within your application’s root directory, add the package(s) to your application’s dependencies within the require braces in the composer.json file created and run a composer install

and this would go ahead to add all the packages you required into the application via a vendor folder.

PHP Packages

There are so many packages currently being managed by packagist. You can go through them on packagist’s website “packagist.org”. Interesting packages that you could check up on are:

PHP Frameworks

Screen-Shot-2015-10-17-at-2.04.26-PM

Framework is the structure that you can choose to build your program on. It can allow you to connect to many different API’s as well as determine the structure of your own application. It provides scaffolding that can allow you to develop faster/more cleanly. It provides toolsets for both UI components and the underlying database access. Frameworks make your life easier by simplifying complex problems so you can focus on finishing the project at hand.

PHP frameworks are just sets of libraries coupled together that makes the life of a web developer easier by hiding so many complexities and providing several utilities like Caching, Authentication, Scheduling, Queues, Encryption, Localization and other useful functionalities out of the box. There are many PHP frameworks available today, and thus developers are sure to find a framework that fits their needs in terms of features, support, speed, scalability and more. Some of the top frameworks used by developers today include: Laravel, The Zend Framework, CakePHP, Symfony, CodeIgniter, Slim and Seagull.

The Slim framework is an awesome framework that can be used to create RESTful APIs in PHP very easily and fast. Slim is a lightweight PHP framework in the sense that it doesn’t take up a lot of space as compared to some other frameworks. Laravel and Zend are also awesome frameworks in PHP but in building fast and simple applications, the slim framework is a lot more useful.

Testing in PHP

Screen-Shot-2015-10-17-at-2.05.16-PMTesting in PHP is extremely possible and can be done with testing frameworks like phpunit, phpspec, codeception etc.

CONCLUSION

All in all, I hope I have been able to clear your doubts about PHP and convinced you it isn’t shitty as you perceived it to be. All you have to do is change your mindset.

Screen-Shot-2015-10-17-at-2.08.17-PM

Hollup, Hollup, Hollup… Before you rush off to start exploring the goodness of PHP and telling your friends about how this written sermon has just changed your life, let me just drop this:

Screen-Shot-2015-10-17-at-2.08.48-PM

Editor’s Note: This post originally appeared on Goodheads.

About the Author

Oduye Oluwayemisi is a Geek, Nerd, Full Stack Software Developer, PHP Advocate, JavaScript Publicist, Laravel Slinger, Music Lover, Candy Crush Addict, Tripolar. Writer by inspiration. Lazy blogger. Creator of amachef.com. Software Developer at The Andela Institute. To know more about the author: www.oluwayemisioduye.com.

Photo Credit: Eli White via Compfight cc

The Cabal Author

Get the best African tech newsletters in your inbox