CodeMusings

Kick back and get started at your own pace.

Skip to Content

Overview

PHP: Hypertext Preprocessor has become a very popular scripting language in the Web development domain, as its standard library has many great tools especially suited for server-side Web development. PHP is an interpreted, loosely, and weakly typed language.

Hello, world!

PHP code is executed between the PHP open and close tags.

hello.php

  1. <?php
  2. echo "Hello, world\n";
  3. ?>

History

Rasmus Lerdorf

Rasmus Lerdorf started with just a simple tool, and helped grow one of the most popular scripting languages today.


Photo by: William Stadtwald Demchick. © CC BY-SA 4.0.

PHP is the successor of PHP/FI, which originally stood for "Personal Home Pages/Forms Interpreter," and was developed by Rasmus Lerdorf in 1994. He wanted to make a tool that would help him keep track of visits to his online resume. Eventually, as his server-side tool got more attention, he added more and more support to the implementation. The early PHP/FI implementation more closely resembled server-side includes, in that it utilized HTML comments [php.net].

Andi and Zeev at a PHP conference

Andi Gutmans and Zeev Suraski speak at a PHP conference.


Nuno Loureiro

Eventually, PHP/FI was rewritten as Andi Gutmans and Zeev Suraski of Tel Aviv, Israel became involved. They collaborated with Lerdorf to release PHP 3.0, which more closely resembles modern PHP. PHP's popularity kept growing, and is now in use on what is estimated to be hundreds of millions of domains.

Design

PHP is a fully functional general purpose scripting language, but is especially well suited toward web development. PHP code is executed within delimited special tags: <?php ... ?>. Anything outside of the tags will be output directly. This lends PHP to being very well suited as a template language. A high degree of expedience pervades the standard library, and many functions work in very intuitive ways.

Type System

PHP has a dynamic, loose, and weak typing system, which means that a variable's type depends upon the context in which it occurs. A variable's type may also vary throughout execution of the program. The context-dependent nature of typing means you need to be vigilant in ensuring you resolve any possible ambiguities with type comparisons.

The PHP documentation has tables showing the nature of type comparisons. There are various context-sensitive situations that arise when using a dynamic and loosely typed language like PHP. The documentation has tables showing how expressions behave given various type comparisons.

Comparisons of $x with PHP functions [php.net]
Expression gettype() empty() is_null() isset() boolean: if($x)
$x = ""; string TRUE FALSE TRUE FALSE
$x = null; NULL TRUE TRUE FALSE FALSE
var $x; NULL TRUE TRUE FALSE FALSE
$x is undefined NULL TRUE TRUE FALSE FALSE
$x = array(); array TRUE FALSE TRUE FALSE
$x = false; boolean TRUE FALSE TRUE FALSE
$x = true; boolean FALSE FALSE TRUE TRUE
$x = 1; integer FALSE FALSE TRUE TRUE
$x = 42; integer FALSE FALSE TRUE TRUE
$x = 0; integer TRUE FALSE TRUE FALSE
$x = -1; integer FALSE FALSE TRUE TRUE
$x = "1"; string FALSE FALSE TRUE TRUE
$x = "0"; string TRUE FALSE TRUE FALSE
$x = "-1"; string FALSE FALSE TRUE TRUE
$x = "php"; string FALSE FALSE TRUE TRUE
$x = "true"; string FALSE FALSE TRUE TRUE
$x = "false"; string FALSE FALSE TRUE TRUE

Good for Beginners?

PHP lends itself well to getting immediate results in the Web development domain. It's very easy to get set up. There's no need to manually parse user input from the query string or stdin. It doesn't take too long until you're able to throw together an email contact application, or even a simple application that stores and retrieves records from a relational database (particularly, MySQL).

The unfortunate flip side of this is that people often get applications running before they fully understand the environment in which the applications run. The security implications crop up quickly in web development, and newbie web developers rarely give security any thought when they're trying to just get their applications up and running.

If web development intrigues you, you would do well to learn the basics of computer networks and security, HTTP, Web servers, and especially HTML and CSS, which will be the output of your PHP application.

References

  1. ^ - History of PHP. http://php.net/manual/en/history.php.php. Accessed on: 4 Oct 2014.