Jump to content

PHP

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by SuzieDerkins (talk | contribs) at 10:59, 24 March 2008 (→‎Release history: put back "popularity" section. I think that its contents may be moved, but must be kept.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

PHP
Paradigmimperative, object-oriented
Designed byRasmus Lerdorf
DeveloperThe PHP Group
First appeared1995
Stable release
5.2.5 / November 8, 2007 (2007-11-08)
Preview release
5.3.0-dev and 6.0-dev[1]
Typing disciplineDynamic, weak
OSCross-platform
LicensePHP License
Websitehttp://php.net/
Major implementations
Roadsend PHP, Phalanger, Quercus, Project Zero
Influenced by
C, Perl, Java, C++, C#, Python
Influenced
Php4delphi

PHP (PHP: Hypertext Preprocessor) is a computer scripting language, originally designed for producing dynamic web pages. It is mainly used in server-side scripting, but can be used from a command line interface or in standalone graphical applications.[2]

While PHP was originally created by Rasmus Lerdorf in 1994, the main implementation of PHP is now produced by The PHP Group and serves as the de facto standard for PHP as there is no formal specification.[3] Released under the PHP License, the Free Software Foundation considers it to be free software.[4]

PHP is a widely-used general-purpose scripting language that is especially suited for web development and can be embedded into HTML. It generally runs on a web server, taking PHP code as its input and creating web pages as output. It can be deployed on most web servers and on almost every operating system and platform free of charge.[5] PHP is installed on more than 20 million websites and 1 million servers, although the number of websites with PHP installed has declined since August 2005.[6] It is also the most popular Apache module among computers using Apache as a web server.[6] The most recent major release of PHP was version 5.2.0 on November 2 2006.[7]

History

Rasmus Lerdorf, who wrote the original Common Gateway Interface binaries

PHP began as a set of Common Gateway Interface binaries written in the C programming language in 1994 by the Danish/Greenlandic programmer Rasmus Lerdorf. Lerdorf initially created these Personal Home Page Tools to replace a small set of Perl scripts he had been using to maintain his personal homepage. The tools were originally created to perform tasks such as displaying his résumé and recording how much traffic his page was receiving.[3] He combined these binaries with his Form Interpreter to create PHP/FI, which had more functionality. It included a larger C implementation which could communicate with databases and helped build simple, dynamic web applications. He released PHP publicly on June 8 1995 to speed up the finding of bugs and improving the code.[8] This release was named PHP version 2, and already had basic functionality that PHP has today. This includes Perl-like variables, form handling, and the ability to embed HTML. The syntax was similar to Perl but was more limited, simpler, and less consistent.[3]

Andi Gutmans, who, along with Zeev Suraski, rewrote the parser that formed PHP 3

Zeev Suraski and Andi Gutmans, two Israeli developers at the Technion IIT, rewrote the parser in 1997 and formed the base of PHP 3, changing the language's name to the recursive initialism PHP: Hypertext Preprocessor.[3] The development team officially released PHP/FI 2 in November 1997 after months of beta testing. Afterwards, public testing of PHP 3 began, 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.[9] They also founded Zend Technologies in Ramat Gan, Israel, which actively manages the development of PHP.[3]

On May 22 2000, PHP 4, powered by the Zend Engine 1.0, was released.[3] On July 13 2004, PHP 5 was released and is powered by the new Zend Engine II.[3] PHP 5 included new features such as improved support for object-oriented programming, the PHP Data Objects extension (which defines a lightweight and consistent interface for accessing databases), and numerous performance enhancements.[10] The most recent update released by The PHP Group is for the older PHP version 4 code branch. As of January 2008, this branch is up to version 4.4.8. PHP 4 will be supported by security updates until August 8 2008.[11]

Currently, PHP 5 is the only stable version that is being actively developed. Active development on PHP 4 ceased at the end of 2007, apart from the critical security updates for PHP 4 already mentioned.[12][11] PHP 6 is currently under development, and major changes include the removal of register_globals, magic quotes, and safe mode.[11][13] Many high profile open source projects ceased to support PHP 4 in new code as of February 5 2008, due to the GoPHP5 initiative, provided by a consortium of PHP developers promoting the transition from PHP 4 to PHP 5.[14][15]

Release history

Version Release date Notable changes References
PHP 1.0 June 8 1995 Officially called "Personal Home Page Tools (PHP Tools)". This is the first use of the name "PHP". [3]
PHP 2.0 April 16 1996 Considered by its creator as the "fastest and simplest tool" for creating dynamic web pages. [3]
PHP 3.0 June 6 1998 Development moves from one person to multiple developers. Zeev Suraski and Andi Gutmans rewrite the base for this version. [3]
PHP 4.0.0 May 22 2000 Added more advanced two-stage parse/execute tag-parsing system called the Zend engine. [16]
PHP 4.1.0 December 10 2001 Introduced the superglobals ($_GET, $_POST, $_SESSION, etc.) [16]
PHP 4.2.0 April 22 2002 Disabled register_globals by default. [16]
PHP 4.3.0 December 27 2002 Introduced the CLI, in addition to the CGI. [16]
PHP 4.4.0 July 11 2005 Added man pages for phpize and php-config scripts. [16]
PHP 5.0.0 July 13 2004 Zend Engine II with a new object model. [7]
PHP 5.1.0 November 24 2005 Performance improvements with introduction of compiler variables in re-engineered PHP Engine. [7]
PHP 5.2.0 November 2 2006 Enabled the filter extension by default. [7]

Popularity

PHP is currently the most popular Apache module among servers using Apache as a web server.[6] Among currently existing computer programming languages, it is the fourth most popular, ranked only behind Java, C, and Visual Basic.[17]

One unfortunate consequence of the popularity of PHP provides a measure of this popularity. Because PHP is easily available and widely used, it attracts hackers who exploit vulnerable applications written in PHP. Software vulnerabilities related to PHP are identified among the CVE (Common Vulnerabilities and Exposures) records, available from the National Vulnerability Database. The proportion of vulnerabilities related to PHP, out of the total of all common vulnerabilities, amounted to: 12% in 2003, 20% in 2004, 28% in 2005, 43% in 2006, 36% in 2007, and 38% for the first two months of 2008. More than a quarter of all software vulnerabilities listed in this database are related to PHP, and more than a third of vulnerabilities listed recently. Moreover, most of these vulnerabilities can be exploited remotely, that is without being logged on the computer hosting the vulnerable application.[18]

Such exploitation is made possible due to poor programming habits, such as failing to check data before entering it into a database, and deprecated features of the language, such as register_globals, which converts variables created by anyone to local variables and can result in code injection, cross-site scripting and other application security issues.[19]

Usage

PHP is a widely-used general-purpose scripting language that is especially suited for web development and can be embedded into HTML. PHP generally runs on a web server, taking PHP code as its input and creating web pages as output. However, it can also be used for command-line scripting and client-side GUI applications. PHP can be deployed on most web servers and on almost every operating system and platform free of charge. The PHP Group also provides the complete source code for users to build, customize and extend for their own use.[5]

PHP primarily acts as a filter.[20] The PHP program takes input from a file or stream containing text and special PHP instructions and outputs another stream of data for display. From PHP 4, the PHP parser compiles input to produce bytecode for processing by the Zend Engine, giving improved performance over its interpreter predecessor.[21]

Originally designed to create dynamic web pages, PHP's principal focus is server-side scripting.[22] While running the PHP parser with a web server and web browser, the PHP model can be compared to other server-side scripting languages such as Microsoft's ASP.NET system, Sun Microsystems' JavaServer Pages, and mod_perl as they provide dynamic content to the client from a web server.[23] To more directly compete with the "framework" approach taken by these systems, Zend is working on the Zend Framework - an emerging set of PHP building blocks and best practices;[24] other PHP frameworks along the same lines include CakePHP, PRADO and Symfony.[25]

The LAMP architecture has become popular in the web industry as a way of deploying inexpensive, reliable, scalable, and secure web applications. PHP is commonly used as the P in this bundle alongside Linux, Apache and MySQL, although the P can also refer to Python or Perl. PHP can be used with many relational database management systems; it runs on all of the most popular web servers and is available for many different operating systems. This flexibility means that PHP has a wide installation base across the Internet. As of April 2007, over 20 million Internet domains were hosted on servers with PHP installed.[6]

Syntax

Syntax-highlighted PHP code

PHP only parses code within its delimiters. Anything outside its delimiters is sent directly to the output and is not parsed by PHP. The most common delimiters are <?php and ?>, which are open and close delimiters respectively. <script language="php"> and </script> delimiters are also available. Short tags (<? or <?= and ?>) are also commonly used, but like ASP-style tags (<% or <%= and %>), they are less portable as they can be disabled in the PHP configuration. For this reason, the use of short tags and ASP-style tags is discouraged.[26] The purpose of these delimiters is to separate PHP code from non-PHP code, including HTML. Everything outside the delimiters is ignored by the parser and is passed through as output.[27]

Variables are prefixed with a dollar symbol and a type does not need to be specified in advance. Unlike function and class names, variable names are case sensitive. Both double-quoted ("") and heredoc strings allow the ability to embed the variable's value into the string.[28] PHP treats newlines as whitespace in the manner of a free-form language (except when inside string quotes), and statements are terminated by a semicolon.[29] PHP has three types of comment syntax: /* */ serves as block comments, and // as well as # are used for inline comments.[30] To output text to the browser, either the print function or the echo function is used. Both functions are nearly identical; the major difference is that print is slower than echo because the former will return a status indicating if it was successful or not, whereas the latter does not return a status and only returns the text for output.[31]

Data types

PHP stores whole numbers in a platform-dependent range. This range is typically that of 32-bit signed integers. Integer variables can be assigned using decimal (positive and negative), octal, and hexadecimal notations. Real numbers are also stored in a platform-specific range. They can be specified using floating point notation, or two forms of scientific notation.[32] PHP has a native Boolean type that is similar to the native Boolean types in Java and C++. Using the Boolean type conversion rules, non-zero values are interpreted as true and zero as false, as in Perl.[32] The null data type represents a variable that has no value. The only value in the null data type is NULL.[32] Variables of the "resource" type represent references to resources from external sources. These are typically created by functions from a particular extension, and can only be processed by functions from the same extension; examples include file, image, and database resources.[32] Arrays can contain elements of any type that PHP can handle, including resources, objects, and even other arrays. Order is preserved in lists of values and in hashes with both keys and values, and the two can be intermingled.[32] PHP also supports strings, which can be used with single quotes, double quotes, or heredoc syntax.[33]

Functions

PHP has hundreds of base functions and thousands more from extensions. Functions are not first-class functions and can only be referenced by their name. [34] User-defined functions can be created at any time without being prototyped.[34] Functions can be defined inside code blocks, permitting a run-time decision as to whether or not a function should be defined. Function calls must use parentheses, with the exception of zero argument class constructor functions called with the PHP new operator, where parentheses are optional. PHP supports quasi-anonymous functions through the create_function() function, although they are not true anonymous functions because anonymous functions are nameless, but functions can only be referenced by name in PHP.[34]

Objects

Basic object-oriented programming functionality was added in PHP 3.[3] Object handling was completely rewritten for PHP 5, expanding the feature set and enhancing performance.[35] In previous versions of PHP, objects were handled like primitive types.[35] The drawback of this method was that the whole object was copied when a variable was assigned or passed as a parameter to a method. In the new approach, objects are referenced by handle, and not by value. PHP 5 introduced private and protected member variables and methods, along with abstract classes and final classes as well as abstract methods and final methods. It also introduced a standard way of declaring constructors and destructors, similar to that of other object-oriented languages such as C++, and a standard exception handling model. Furthermore, PHP 5 added interfaces and allowed for multiple interfaces to be implemented. There are special interfaces that allow objects to interact with the runtime system. Objects implementing ArrayAccess can be used with array syntax and objects implementing Iterator or IteratorAggregate can be used with the foreach language construct. There is no virtual table feature in the engine, so static variables are bound with a name instead of a reference at compile time.[36]

If the developer creates a copy of an object using the reserved word clone, 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 the object's properties. If a __clone() method is defined, then it will be responsible for setting the necessary properties in the created object. For convenience, the engine will supply a function that imports the properties of the source object, so that the programmer can start with a by-value replica of the source object and only override properties that need to be changed.[37]

Resources

PHP includes free and open source libraries with the core build. PHP is a fundamentally Internet-aware system with modules built in for accessing FTP servers, many database servers, embedded SQL libraries such as embedded MySQL and SQLite, LDAP servers, and others. Many functions familiar to C programmers such as those in the stdio family are available in the standard PHP build.[38]

PHP allows developers to write extensions in C to add functionality to the PHP language. These can then be compiled into PHP or loaded dynamically at runtime. Extensions have been written to add support for the Windows API, process management on Unix-like operating systems, multibyte strings (Unicode), cURL, and several popular compression formats. Some more unusual features include integration with Internet relay chat, dynamic generation of images and Adobe Flash content, and even speech synthesis. The PHP Extension Community Library (PECL) project is a repository for extensions to the PHP language.[39]

As with many scripting languages, PHP scripts are normally kept as human-readable source code, even on production web servers.[40] While this allows flexibility, it can raise issues with security and performance.[41] For example, if a hacker acquires control of a server with PHP scripts, they can see the code because PHP code is interpreted and not compiled. This means that the PHP engine reads every line of the code every time the script is run, and converts it to computer code on the fly.[42]

Code optimizers improve the quality of the compiled code by reducing its size and making changes that can reduce the execution time and improve performance. The nature of the PHP compiler is such that there are often many opportunities for code optimization.[43] An example of a code optimizer is the Zend Optimizer, which requires an application to be installed on the server to improve the performance of PHP scripts.[44]

Accelerators offer performance gains by caching the compiled form of a PHP script in shared memory to avoid the overhead of parsing and compiling the code every time the script runs. They may also perform code optimization to provide increased execution performance.[45] Both commercial and open source accelerators are available.[46][47]

See also

Notes

  1. ^ "PHP Snapshots". The PHP Group. Retrieved 2008-03-16.
  2. ^ "Introduction". PHP Manual. Retrieved 2006-11-15.
  3. ^ a b c d e f g h i j k "History of PHP and related projects". The PHP Group. Retrieved 2008-02-25.
  4. ^ "GPL-Incompatible, Free Software Licenses". Various Licenses and Comments about Them. Free Software Foundation. Retrieved 2008-02-22.
  5. ^ a b "Embedding PHP in HTML". O'Reilly. 2001-05-03. Retrieved 2008-02-25.
  6. ^ a b c d "PHP: PHP Usage Stats". SecuritySpace. 2007-04-01. Retrieved 2008-02-24.
  7. ^ a b c d "PHP: PHP 5 ChangeLog". The PHP Group. 2007-11-08. Retrieved 2008-02-22.
  8. ^ Lerdorf, Rasmus (1995-06-08). "Announce: Personal Home Page Tools (PHP Tools)". Newsgroupcomp.infosystems.www.authoring.cgi. Retrieved 2006-09-17. {{cite newsgroup}}: Check date values in: |date= (help)
  9. ^ "Zend Engine version 2.0: Feature Overview and Design". Zend Technologies Ltd. Retrieved 2006-09-17.
  10. ^ Trachtenberg, Adam (2004-07-15). "Why PHP 5 Rocks!". O'Reilly. Retrieved 2008-02-22.
  11. ^ a b c "php.net 2007 news archive". The PHP Group. 2007-07-13. Retrieved 2008-02-22.
  12. ^ Kerner, Sean Michael (2008-02-01). "PHP 4 is Dead—Long Live PHP 5". InternetNews. Retrieved 2008-03-16.
  13. ^ "Prepare for PHP 6". CorePHP. 2005-11-23. Retrieved 2008-03-24.
  14. ^ GoPHP5. "PHP projects join forces to Go PHP 5" (PDF). GoPHP5 Press Release. Retrieved 2008-02-23.{{cite web}}: CS1 maint: numeric names: authors list (link)
  15. ^ "GoPHP5". GoPHP5. Retrieved 2008-02-22.
  16. ^ a b c d e "PHP: PHP 4 ChangeLog". The PHP Group. 2008-01-03. Retrieved 2008-02-22.
  17. ^ "TIOBE Programming Community Index for March 2008". TIOBE. 2008-03-01. Retrieved 2008-03-07.
  18. ^ "PHP-related vulnerabilities on the National Vulnerability Database". 2008-03-01.
  19. ^ "Using Register Globals". 2008-03-08. Retrieved 2008-03-08.
  20. ^ "What does PHP do?". The PHP Group. Retrieved 2008-02-25.
  21. ^ "PHP and MySQL". University of Alabama. Retrieved 2008-02-25.
  22. ^ "PHP Server-Side Scripting Language". Indiana University. 2007-04-04. Retrieved 2008-02-25.
  23. ^ "JavaServer Pages Technology - JavaServer Pages Comparing Methods for Server-Side Dynamic Content White Paper". Sun Microsystems. Retrieved 2008-02-25.
  24. ^ "Why Zend Framework?". Zend Technologies. Retrieved 2008-02-25.
  25. ^ "CakePHP". CakePHP. Retrieved 2008-02-25.
  26. ^ "PHP: Basic syntax". The PHP Group. Retrieved 2008-02-22.
  27. ^ "Your first PHP-enabled page". The PHP Group. Retrieved 2008-02-25.
  28. ^ "Variables". The PHP Group. Retrieved 2008-03-16.
  29. ^ "Instruction separation". The PHP Group. Retrieved 2008-03-16.
  30. ^ "Comments". The PHP Group. Retrieved 2008-03-16.
  31. ^ "print". The PHP Group. Retrieved 2008-03-16.
  32. ^ a b c d e "Types". The PHP Group. Retrieved 2008-03-16.
  33. ^ "Strings". The PHP Group. Retrieved 2008-03-21.
  34. ^ a b c "Functions". The PHP Group. Retrieved 2008-03-16.
  35. ^ a b "PHP 5 Object References". mjtsai. Retrieved 2008-03-16.
  36. ^ "Classes and Objects (PHP 5)". The PHP Group. Retrieved 2008-03-16.
  37. ^ "Object cloning". The PHP Group. Retrieved 2008-03-16.
  38. ^ "PHP Function List". The PHP Group. Retrieved 2008-02-25.
  39. ^ "Developing Custom PHP Extensions". devnewz. 2002-09-09. Retrieved 2008-02-25.
  40. ^ (Gilmore 2006, p. 43)
  41. ^ Doll, Shelley (2002-04-12). "Zend Encoder safeguards your PHP source". TechRepublic. Retrieved 2008-03-16.
  42. ^ "PHP On-The-Fly!". Developer Tutorials. Retrieved 2008-03-16.
  43. ^ "A HOWTO on Optimizing PHP". phpLens. Retrieved 2008-02-25.
  44. ^ "Setting Up Zend Optimizer Tutorial". WebHostGear. Retrieved 2008-03-16.
  45. ^ "eAccelerator". eAccelerator. Retrieved 2008-02-25.
  46. ^ "Zend Online Store". Zend. Retrieved 2008-03-16.
  47. ^ "Download eAccelerator". eAccelerator. Retrieved 2008-03-16.

References

Further reading