Jump to content

PHP

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by StefenTower (talk | contribs) at 13:37, 22 July 2004 (External links: Alphabetized sections). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

For the "PHP" Cold-war history project, see Parallel History Project.


File:Php-med-trans.png
PHP logo

PHP (a recursive acronym for "PHP: Hypertext Preprocessor") is a widely-used open-source programming language primarily for server-side applications and developing dynamic web content. Famous examples of PHP applications include phpBB and MediaWiki, the software behind Wikipedia. The PHP model can be seen as an alternative to Microsoft's ASP/VBScript/JScript system, Sun Microsystems' JSP/Java system, and to the CGI/Perl system.

PHP's ease of use and similarity with the most common structured programming languages – most notably C and Perl – allows most experienced programmers to start developing complex applications with a minimal learning curve. It also enables experienced developers to get involved with dynamic web content applications without having to learn a whole new set of functions and practices.

One of the more attractive parts of PHP is that it is more than just a scripting language. Thanks to its modular design, PHP is also used to develop GUI applications, and can be used from the command line just like Perl or Python.

PHP allows easy interaction with a large number of relational database systems, such as Oracle, DB2, MySQL, and PostgreSQL, while maintaining a simple and straightforward syntax. PHP runs on most major operating systems, including UNIX, Linux, Windows, and Mac OS X, and can interact with many major web servers. The official PHP website contains extensive documentation. The Linux, Apache, MySQL, PHP (LAMP) architecture has become very popular in the Web industry as a way of deploying inexpensive, reliable, scalable, secure web applications. (The 'P' in LAMP can also stand for Perl or Python.)

PHP is the result of the collective efforts of many contributors. It is licensed under a BSD-style license, the PHP license. PHP, from version 4, has been powered by the Zend engine.

History

PHP was originally designed as a set of Perl scripts by Rasmus Lerdorf in 1994 to display his résumé and collect some data, such as how many hits it was generating. Others first used "Personal Home Page Tools" in 1995, when Lerdorf had combined it with his own Form Interpreter to create PHP/FI. Zeev Suraski and Andi Gutmans, two Israeli developers of the Technion - Israel Institute of Technology, rewrote the parser in 1997 and formed the base of PHP 3. They also changed the name to its current recursive form. After months in beta, the development team officially released PHP/FI 2 in November 1997. Public testing of PHP 3 began immediately and the official launch came in June 1998. Suraski and Gutmans then started a new rewrite of PHP's core, producing the Zend engine in 1999. In May 2000, PHP 4, powered by the Zend Engine, was released. On July 13, 2004, PHP 5 was released, powered by Zend Engine 2.

Popularity of PHP

PHP is currently one of the most popular server-side scripting systems on the Web. It has been widely adopted since the release of version 4, which was the first version powered by the powerful Zend Engine.

One major part of PHP which has helped it become popular is that it is a very loose language. That is, the rules aren't as strict with variables and the like. For example, you never need to declare a variable and they can be of any type. All variables start with the "$" sign. Also, arrays can be created and then hold anything in them. Unlike many other languages (like C++ and Java) they will be able to hold different variable types, and even other arrays if you so desire. All of this "loose-ness" makes it very easy to do many things.

According to Netcraft's April 2002 survey, PHP is now the most deployed server-side scripting language, running on around 9 of the 37 million domains in their survey. This is confirmed by PHP's own figures, which show PHP usage (measured on a per-domain basis) growing at around 5% per month. In May 2003, almost 13 million domains were using PHP, based on the same source.[1]

Due to PHP's popularity, a new breed of programmer has emerged – one who is only familiar with PHP, which in turn forced open the door toward a command line interface for PHP, along with support for GUI libraries such as GTK+ and ncurses. This is a major step for PHP, because it represents its adoption as a genuine programming language (i.e. running autonomously on a stand-alone machine, as opposed to its original purpose of serving web pages to client machines from a server).

Code example

<?php
// This is one style for commenting

# This is a second style of commenting

/* This style of commenting
can cover many lines */

// Sets the variable $variable
$variable = 'hello world';
// Lines in PHP that aren't comments or closing braces are ended with semicolons
print $variable;
echo
$variable;
// Both print and echo have the same effect, displaying the specified variable

?>

PHP's libraries

PHP, unlike ASP, has some of the largest free and open-source libraries included with the core build. PHP is a fundamentally Internet-aware system and as such, there are modules built in for accessing FTP servers, all manners of database servers, LDAP servers and much more. In addition to this, many familiar C functions such as the printf family are all available in the standard PHP build.

PHP has a wide variety of extensions such as support for the Windows API, process management on UNIX-like operating systems, cURL, and the ZIP/gzip/bzip2 compression formats. Some of the more unique features are PDF generation, on-the-fly Macromedia Flash generation, integration with Internet relay chat and much more.

This is the present list of all officially documented libraries:

(Source: PHP.net manual)

Object-oriented programming

Up until version 4, PHP had no object-oriented features. In version 4 basic object functionality was added, but the implementation still lacked the powerful and useful features of other object-oriented languages like C++ and Java.

In version 5, which was released in July 2004, PHP's object-oriented functionality has been very much enhanced and is more robust and complete. Here is a summary of some of the changes in PHP 5 (powered by Zend Engine 2):

New Object Model.
PHP's handling of objects has been completely rewritten, allowing for better performance and more features. In previous versions of PHP, objects were handled like primitive types (for instance integers and strings). The drawback of this method was that semantically the whole object was copied when a variable was assigned, or pass as a parameter to a method. In the new approach, objects are referenced by handle, and not by value (one can think of a handle as an object's identifier).
Private and Protected Members
PHP 5 introduces private and protected member variables, they allow you to define the visibility of class properties.
Private and protected methods
Private and protected methods are also introduced.
Abstract Classes and Methods
PHP 5 also introduces abstract classes and methods. An abstract method only declares the method's signature and does not provide an implementation. A class that contains abstract methods needs to be declared abstract.
Interfaces
A class may implement an arbitrary list of interfaces.
Object Cloning
If the developer asks to create a new copy of an object, the Zend engine will check if a __clone() method has been defined or not. If not, it will call a default __clone() which will copy all of the object's properties. If a __clone() method is defined, then it will be responsible to set the necessary properties in the created object. For convenience, the engine will supply a function that imports all of the properties from the source object, so that they can start with a by-value replica of the source object, and only override properties that need to be changed.
Unified Constructors
PHP 5 introduces a standard way of declaring constructor methods by calling them by the name __construct().
Destructors
PHP 5 introduces a destructor concept similar to that of other object-oriented languages, such as Java: When the last reference to an object is destroyed the object's destructor, which is a class method named __destruct() that receives no parameters, is called before the object is freed from memory.
Exceptions
PHP 4 had no exception handling. PHP 5 introduces a exception model similar to that of other programming languages.

More additions and examples of the additions mentioned above are available on this page.

Caching and optimization

Because PHP is an interpreted language, performance of PHP can, at times, be problematic. A number of PHP cache systems exist to speed up PHP processing. Some examples include:

Support

Although the PHP development team does not provide programming help directly, there are many excellent help resources available for the novice PHP programmer. Worth mentioning are the PHP mailing lists, the Usenet group comp.lang.php (available on PHP.net's news server), and the IRC channels #php and #phphelp on EFNet, IRCNet, DALnet and other networks. There is also a PHP user group registry.

Software built with PHP (not noted above)

Template:List of programming languages