PHP 101

Disclaimer: I need to learn PHP at my new workplace so I’ve decided to do some research and write a blurb about it. I am by no means a PHP expert!

Personal Home Page, recognized as “PHP” by the developer community, was launched in 1995 by a Greelandic Canadian man named Rasmus Lerdorf. PHP derived from Lerdorf’s work on CGI binaries in C, which was used to maintain his personal homepage (hence the name “PHP”).

Rasmus Lerdorf, the father of PHP

In 1997, two Israeli programmers, Zeev Suraski and Andi Gutmans, rewrote the parser which led to the development of PHP 3 — now known by its recursive acronym “Hypertext Preprocessor”. In 2015, PHP has reached version 7 and has been used to build big-name sites including Facebook, Flickr, Wordpress, and Wikipedia.

PHP is a server-side scripting language that generates HTML information dynamically. PHP is built on top of a web server software (e.g., Apache). Once PHP code is interpreted and generates proper HTML, the web server sends the resulting output to its client.

PHP Frameworks

PHP Framework Popularity at Work (2015). Sample size > 7800. Source: SitePoint.com

CodeIgniter: CodeIgniter is an open-source PHP framework first released in 2006 by a Canadian team based at the British Columbia Institute of Technology. It somewhat follows the MVC (Model-View-Controller) pattern, though it does not require models or views. What makes CodeIgniter so great? It’s “faster, lighter and the least like a framework" (Rasmus Lerdorf).

Laravel: Laravel is an open source PHP framework built by Taylor Otwell in 2011 and based on the MVC architectural pattern. It was created as an extension of CodeIgniter, which doesn’t have features such as support for user authentication and authorization.

Symfony2: Symfony was first released in 2005 and developed by a French team led by Fabien Potencier. It’s commonly used in an enterprise context and was built for speed — e.g., replacing repetitive coding tasks. The foundation of Symfony was inspired by other MVC frameworks including Ruby on Rails and Django. Symfony compnents are also used in Laravel.

CakePHP: CakePHP is a “rapid development” framework that started in 2005 by Polish programmer Michal Tatarynowicz. It’s built off of concepts from Ruby on Rails and incorporates software design principles such as MVC, ActiveRecord (storage of in-memory object data in relational databases), and Association Data Mapping (joint tables using foreign keys to create many-to-many relationships between database tables). “CakeFest” is an annual global conference that involves all things CakePHP.

Microframeworks: Microframeworks help quickly write lightweight minimalistic web applications and APIs. They usually don’t have the core features of full web apps such as authorization, authentication, database abstraction, and input validation. Common PHP microframeworks include Slim, Silex, Phalcon and Jolt.

PHP Drawbacks

PHP is a notorious language in the developer community. In one Quora article, a software developer admits “writing code in PHP feels like a punishment for something I did wrong”. Here are some of PHP’s major drawbacks:

  • Inconsistent language: PHP is a flexible language. Different extensions have been written at different times by different developers which means that there are obvious inconsistencies across APIs and PHP frameworks.
  • “Messy” code: It’s a pain to declare variables and references with $variable (that extra $ is annoying!). The discrepancy between hash syntax ($key[‘value’]) and class syntax ($key->value) means you need to remember which one you’re using or convert one to another. There are also many different global settings in php.ini that can vary from server to server.
  • Security vulnerabilities: SQL injection is a classic attack where “hackers” send special SQL queries to the database that can either modify or delete database tables or even worse, the entire database itself. This happens when developers fail to build any data validation or checking in user inputs. A classic rookie mistake is leaving register globals “on” which presents serious security holes. Let’s say you did leave register_global = ON. If you visit that script in the browser, you could easily append ?authorized=1 to the URL and open up a dangerous can of worms for hackers to easily attack.

PHP Strengths

Though PHP does have its drawbacks, it is still one of the most popular languages used by developers. Here are some of PHP’s strengths:

  • Great documentation is available: PHP has been around for a while, and there are helpful resources for developers to use unlike some other languages out there (e.g., Python, R, etc.).
  • Easy to deploy: PHP is the “lingua franca” of web hosting companies. Just copy the files and you’re done.
  • Less abstract and more transparent: Despite the large quantity of code involved with PHP, there is very little “magic” running behind the scenes which gives the developer more control over their code and facilitates debugging.

What’s been built with PHP?

Though it is controversially dubbed a “bad programming language”, it clearly shows value in building numerous powerful web apps over the past decade. Here are some major sites that are build on PHP:

  1. Facebook
  2. Wikipedia
  3. Flickr
  4. Tumblr
  5. WordPress
  6. MailChimp
  7. Yahoo!
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.