PHP 24131 move=:edit= 226055332 2008-07-16T17:02:30Z 62.38.149.184 /* External links */ {{Otheruses}} {{ infobox programming language | designer = [[Rasmus Lerdorf]] | developer = The PHP Group | implementations = [[Roadsend PHP]], [[Phalanger (compiler)|Phalanger]], Quercus, [[Project Zero]] | influenced = [[Php4delphi]] | influenced_by = [[C (programming language)|C]], [[Perl]], [[Java (programming language)|Java]], [[C++ (programming language)|C++]], [[C Sharp (programming language)|C#]], [[Python (programming language)|Python]] | latest_release_version = 5.2.6 | latest_release_date = {{release date|2008|5|01}} | latest_test_version = 5.3.0-dev and 6.0-dev<ref>{{cite web|accessdate=2008-03-16|url=http://snaps.php.net/|title=PHP Snapshots |publisher=The PHP Group }}</ref> | license = [[PHP License]] | logo = [[Image:PHP-logo.svg|220px]] | operating_system = [[Cross-platform]] | paradigm = [[Imperative programming|imperative]], [[Object-oriented programming|object-oriented]] | typing = Dynamic, weak | year = 1995 | website = http://php.net/ }} '''PHP''' (a [[recursive acronym]]{{unclear|date=July 2008|Recursive how? Processing Hypertext preprocessor... show the language for the rest of us, for tis not obvious. <b>[[User:Fabartus|Fra]]</b><font color="green">[[User talk:Fabartus|nkB]]</font> 02:28, 11 July 2008 (UTC)}} for ''PHP: Hypertext Preprocessor'' and the letters used to stand for 'Personal Home Page tools')<ref>{{cite book |last=Newman |first=Chris |title=Sams Teach Yourself PHP in 10 Minutes |origmonth=April |origyear=2005 |series=Sams Teach Yourself |publisher=Sams Publishing |isbn=0-672-32762-7 |pages=p. 5 }}</ref> is a computer [[scripting language]], originally designed for producing [[dynamic web page]]s. It is for [[server-side scripting]], but can be used from a [[command line interface]] or in [[standalone]] [[Graphical user interface|graphical applications]].<ref>{{cite web | url = http://php.net/manual/en/introduction.php | work = PHP Manual | title = Introduction | accessdate = 2006-11-15 }}</ref> While PHP was originally created by [[Rasmus Lerdorf]] in 1995, the main implementation of PHP is now produced by The PHP Group and serves as the [[de facto standard|''de facto'' standard]] for PHP as there is no [[formal specification]].<ref name="history" /> Released under the [[PHP License]], the [[Free Software Foundation]] considers it to be [[free software]].<ref>{{ cite web | title = GPL-Incompatible, Free Software Licenses | url = http://www.fsf.org/licensing/licenses/index_html#GPLIncompatibleLicenses | work = Various Licenses and Comments about Them | publisher = Free Software Foundation|accessdate=2008-02-22 }}</ref> 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 page]]s as output. It can be deployed on most web servers and on almost every [[operating system]] and [[Platform (computing)|platform]] free of charge.<ref name="foundations" /> PHP is installed on more than 20 million websites and 1 million [[web server]]s.<ref>{{cite web|url=http://www.php.net/usage.php|title=Usage Stats for April 2007|accessdate=2008-07-07}}</ref> It is also the most popular [[Apache HTTP Server|Apache]] module among computers using Apache as a web server.<ref name="usage" /> The most recent major release of PHP was version 5.2.6 on [[May 1]] [[2008]].<ref name="php5changelog" /> ==History== {{triple image|right|Lerdorf.jpg|100|Andi Gutmans 1.jpg|110|Zeev Suraski.jpg | 100 |[[Rasmus Lerdorf]], who wrote the original [[Common Gateway Interface]] binaries, and [[Andi Gutmans]] and [[Zeev Suraski]], who rewrote the [[parser]] that formed PHP 3}}<!-- MOS says no-no to squeezing text between two graphics. --> '''PHP''' originally stood for Personal Home Page. It began in 1994 as a set of [[Common Gateway Interface]] [[Binary file|binaries]] written in the [[C programming language]] by the [[Danish people|Danish]]/[[Greenland]]ic 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 used to perform tasks such as displaying his [[résumé]] and recording how much [[web traffic|traffic]] his page was receiving.<ref name="history" /> He combined these binaries with his Form Interpreter to create PHP/FI, which had more functionality. PHP/FI included a larger [[C (programming language)|C implementation]] and could communicate with [[database]]s enabling the building of simple, dynamic [[web application]]s. He released PHP publicly on [[June 8]] [[1995]] to speed up the finding of [[Software bug|bug]]s and improving the code.<ref>{{cite newsgroup | title = Announce: Personal Home Page Tools (PHP Tools) | author = Lerdorf, Rasmus | date = [[1995-06-08]] | newsgroup = comp.infosystems.www.authoring.cgi | url = http://groups.google.com/group/comp.infosystems.www.authoring.cgi/msg/cc7d43454d64d133 | accessdate = 2006-09-17 }}</ref> This release was named PHP version 2 and already had the basic functionality that PHP has today. This included 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.<ref name="history" /> [[Zeev Suraski]] and [[Andi Gutmans]], two [[Israelis|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''.<ref name="history">{{cite web|accessdate=2008-02-25|url=http://www.php.net/history|title=History of PHP and related projects |publisher=The PHP Group }}</ref> The development team officially released PHP/FI 2 in November 1997 after months of [[development stage#beta|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 (programming)|rewrite]] of PHP's core, producing the [[Zend Engine]] in 1999.<ref>{{cite web | title = Zend Engine version 2.0: Feature Overview and Design | publisher = Zend Technologies Ltd. | url = http://www.zend.com/zend/zend-engine-summary.php | accessdate = 2006-09-17 }}</ref> They also founded [[Zend Technologies]] in [[Ramat Gan]], Israel, which manages the development of PHP.<ref name="history" /> On [[May 22]] [[2000]], PHP 4, powered by the Zend Engine 1.0, was released.<ref name="history" /> On [[July 13]] [[2004]], PHP 5 was released, powered by the new Zend Engine II.<ref name="history" /> 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.<ref>{{cite web|title=Why PHP 5 Rocks!|url=http://www.onlamp.com/pub/a/php/2004/07/15/UpgradePHP5.html|publisher=O'Reilly|accessdate=2008-02-22|date=2004-07-15|author=Trachtenberg, Adam}}</ref> 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 is no longer under active development but will be supported by security updates until [[August 8]] [[2008]].<ref name="2007 news">{{cite web|title=php.net 2007 news archive|url=http://www.php.net/archive/2007.php|publisher=The PHP Group|accessdate=2008-02-22|date=2007-07-13}}</ref><ref>{{cite web|accessdate=2008-03-16|url=http://www.internetnews.com/dev-news/article.php/3725291|title=PHP 4 is Dead—Long Live PHP 5 |publisher=InternetNews|date=2008-02-01|author=Kerner, Sean Michael }}</ref> In 2008, PHP 5 became the only stable version under development. [[Late static binding]] has been missing from PHP and will be added in version 5.3.<ref>{{cite web|url=http://www.digitalsandwich.com/archives/53-Late-Static-Binding-in-PHP.html|accessdate=2008-03-25|title=Late Static Binding in PHP|date=2006-02-23|publisher=Digital Sandwich}}</ref> <ref>{{cite web|accessdate=2008-03-25|url=http://ca3.php.net/language.oop5.static|title=Static Keyword|publisher=The PHP Group}}</ref> Alongside PHP 5, PHP 6 is also under active development. Major changes include the removal of <code>register_globals</code><ref>{{cite web|accessdate=2008-04-04|url=http://uk.php.net/register_globals|title=Using Register Globals|publisher=PHP}}</ref>, [[magic quotes]], and [[Safe mode#Application software safe mode|safe mode]].<ref name="2007 news" /><ref>{{cite web|accessdate=2008-03-24|url=http://www.corephp.co.uk/archives/19-Prepare-for-PHP-6.html|title=Prepare for PHP 6 |publisher=CorePHP|date=2005-11-23 }}</ref> PHP does not have complete native support for [[Unicode]] or multibyte strings;<ref>{{cite web|url=http://www.php.net/~scoates/unicode/render_func_data.php|accessdate=2008-03-25|title=PHP 6 - Unicode Completion Stats|publisher=The PHP Group|date=2008-03-25}}</ref> unicode support will be included in PHP 6.<ref>{{cite web|url=http://www.php.net/~derick/meeting-notes.html#unicode|title=Unicode|accessdate=2008-03-25|publisher=The PHP Group}}</ref> 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.<ref name="gophp5">{{cite web |url=http://gophp5.org/sites/gophp5.org/files/press_release.pdf |title=PHP projects join forces to Go PHP 5 |accessdate=2008-02-23 |work=GoPHP5 Press Release |author=GoPHP5}}</ref><ref>{{cite web|url=http://gophp5.org/|title=GoPHP5|publisher=GoPHP5|accessdate=2008-02-22}}</ref> It runs in both [[32-bit]] and [[64-bit]] environments, but on Windows the only official distribution is 32-bit, requiring Windows 32-bit compatibility mode to be enabled while using [[IIS]] in a 64-bit Windows environment. There is a third-party distribution<ref>{{cite web | url=http://fusionxlan.com/PHPx64.php|title=The PHPx64 Project|accessdate=2008-05-05|work=Fusion-X LAN|author=Fusion-X LAN}}</ref> available for 64-bit Windows. ===Release history=== {| class="wikitable" |- ! ! Meaning |- | style="background-color:#fa8072;" | Red | Old release; not supported |- | style="background-color:#f0e68c;" | Yellow | Old release; still supported |- | style="background-color:#A0E75A;" | Green | Current release |- | style="background-color:#87CEEB;" | Blue | Future release |} <!-- RELEASE HISTORY --> {| class="wikitable" ! Major Version !! Minor Version !! Release date !! Notes |- !1.0 | style="background-color:#fa8072;" | 1.0.0 |[[1995-06-08]] |Officially called "Personal Home Page Tools (PHP Tools)". This is the first use of the name "PHP".<ref name="history" /> |- !2.0 | style="background-color:#fa8072;" | 2.0.0 |[[1996-04-16]] |Considered by its creator as the "fastest and simplest tool" for creating dynamic web pages.<ref name="history" /> |- !3.0 | style="background-color:#fa8072;" | 3.0.0 |[[1998-06-06]] |Development moves from one person to multiple developers. Zeev Suraski and Andi Gutmans rewrite the base for this version.<ref name="history" /> |- !rowspan="6"|4.0 | style="background-color:#fa8072;" | 4.0.0 |[[2000-05-22]] |Added more advanced two-stage parse/execute tag-parsing system called the Zend engine.<ref name="php4changelog">{{cite web|title=PHP: PHP 4 ChangeLog|url=http://www.php.net/ChangeLog-4.php|publisher=The PHP Group|accessdate=2008-02-22|date=2008-01-03}}</ref> |- | style="background-color:#fa8072;" | 4.1.0 |[[2001-12-10]] |Introduced 'superglobals' (<code>$_GET</code>, <code>$_POST</code>, <code>$_SESSION</code>, etc.)<ref name="php4changelog" /> |- | style="background-color:#fa8072;" | 4.2.0 |[[2002-04-22]] |Disabled register_globals by default. Data received over the network is not inserted directly into the [[Global variable|global]] namespace anymore, closing possible security holes in applications.<ref name="php4changelog" /><ref name="register_globals" /> |- | style="background-color:#fa8072;" | 4.3.0 |[[2002-12-27]] |Introduced the CLI, in addition to the CGI.<ref name="php4changelog" /> |- | style="background-color:#fa8072;" | 4.4.0 |[[2005-07-11]] |Added man pages for <code>phpize</code> and <code>php-config</code> scripts.<ref name="php4changelog" /> |- | style="background-color:#fa8072;" | 4.4.8 |[[2008-01-03]] |Several security enhancements and bug fixes. End of life release for PHP 4. Security updates only until 2008-08-08, if necessary.<ref>[http://www.php.net/downloads.php#v4 PHP: Downloads<!-- Bot generated title -->]</ref><ref>[http://www.php.net/releases/4_4_8.php PHP: PHP 4.4.8 Release Announcement<!-- Bot generated title -->]</ref> |- !rowspan="5"|5.0 | style="background-color:#fa8072;" | 5.0.0 |[[2004-07-13]] |Zend Engine II with a new object model.<ref name="php5changelog">{{cite web|title=PHP: PHP 5 ChangeLog|url=http://www.php.net/ChangeLog-5.php|publisher=The PHP Group|accessdate=2008-02-22|date=2007-11-08}}</ref> |- | style="background-color:#fa8072;" | 5.1.0 |[[2005-11-24]] |Performance improvements with introduction of compiler variables in re-engineered PHP Engine.<ref name="php5changelog" /> |- | style="background-color:#f0e68c;" | 5.2.0 |[[2006-11-02]] |Enabled the filter extension by default.<ref name="php5changelog" /> |- | style="background-color:#A0E75A;" | 5.2.6 |[[2008-05-01]]<ref>[http://www.php.net/archive/2008.php#id2008-05-01-1 PHP: News Archive - 2008<!-- Bot generated title -->]</ref> |Several security enhancements and bug fixes<ref>[http://www.php.net/archive/2008.php#id2008-05-01-1 PHP: News Archive - 2008<!-- Bot generated title -->]</ref> |- | style="background-color:#87CEEB;" | 5.3.0 |No date set |[[Namespace_%28computer_science%29|Namespace]] support; Improved XML support through use of XMLReader and XMLWriter; SOAP support <ref>[http://devzone.zend.com/node/view/id/2739 Zend Weekly Summaries Issue #359<!-- Bot generated title -->]</ref>, Late static bindings, Jump label (limited [[goto]]) |- !6.0 | style="background-color:#87CEEB;" | 6.0.0 |No date set |[[Unicode]] support; removal of 'ereg()', 'register_globals', 'magic_quotes' and 'safe_mode'; Alternative PHP Cache; Removal of mime_magic and rewrite of fileinfo() for better [[MIME]] support<ref>[http://jero.net/articles/php6 Personal homepage of Jeroen van der Meer<!-- Bot generated title -->]</ref> |} ==Usage== PHP is used by many famous companies, including [[YouTube]] for example<ref>http://youtube.com/index.php</ref>. The user-facing portion of [[Facebook]] is also written in PHP<ref>http://blog.facebook.com/blog.php?post=2356432130</ref><ref>http://www.facebook.com/index.php</ref>. Even [[Wikipedia]] ([[Mediawiki]]) is written in [[PHP]]<ref>http://www.mediawiki.org/wiki/Index.php</ref><ref>http://objectmix.com/python/391069-python-slow.html</ref>. PHP is a general-purpose scripting language that is especially suited for [[web development]]. PHP generally runs on a [[web server]], taking PHP code as its input and creating [[web page]]s as output. It can also be used for [[command-line]] scripting and [[client-side]] [[Graphical user interface|GUI]] applications. PHP can be deployed on most [[web server]]s, many [[operating system]]s and [[Platform (computing)|platform]]s, and can be used with many [[relational database management system]]s. It is available free of charge, and the PHP Group provides the complete source code for users to build, customize and extend for their own use.<ref name="foundations">{{cite web|accessdate=2008-02-25|url=http://www.onlamp.com/pub/a/php/2001/05/03/php_foundations.html|title=Embedding PHP in HTML |publisher=O'Reilly|date=2001-05-03 }}</ref> PHP primarily acts as a [[Filter (software)|filter]]<ref>{{cite web|accessdate=2008-02-25|url=http://gtk.php.net/manual1/it/html/intro.whatis.php.whatdoes.html|title=What does PHP do? |publisher=The PHP Group }}</ref>, taking input from a file or stream containing text and/or PHP instructions and outputs another stream of data; most commonly the output will be HTML. It can automatically detect the language of the user.<ref>[http://techpatterns.com/downloads/php_language_detection.php PHP Language Detection :: Detect System Languages, set headers :: $_SERVER["HTTP_ACCEPT_LANGUAGE"&#93;<!-- Bot generated title -->]</ref><ref>[http://urbanoalvarez.es/blog/2008/04/01/language-detection-php/ Visitor’s language detection in php | Urbano's Blog<!-- Bot generated title -->]</ref> From PHP 4, the PHP [[parser]] [[compiler|compiles]] input to produce [[bytecode]] for processing by the [[Zend Engine]], giving improved performance over its [[Interpreter (computing)|interpreter]] predecessor.<ref>{{cite web|accessdate=2008-02-25|url=http://cs.ua.edu/457/Notes/PHP%20and%20MySQL.ppt|title=PHP and MySQL |publisher=University of Alabama }}</ref> Originally designed to create dynamic web pages, PHP's principal focus is [[server-side scripting]]<ref>{{cite web|url=http://webmaster.iu.edu/PHPlanguage/index.shtml|title=PHP Server-Side Scripting Language|publisher=Indiana University|accessdate=2008-02-25|date=2007-04-04}}</ref>, and it is similar to other server-side scripting languages that provide dynamic content from a web server to a [[client (computing)|client]], such as [[Microsoft]]'s [[ASP.NET]] system, [[Sun Microsystems]]' [[JavaServer Pages]]<ref>{{cite web|url=http://java.sun.com/products/jsp/jspservlet.html|title=JavaServer Pages Technology - JavaServer Pages Comparing Methods for Server-Side Dynamic Content White Paper|publisher=Sun Microsystems|accessdate=2008-02-25}}</ref>, and [[mod_perl]]<!-- DO NOT AUTO-CORRECT THIS. IT HAS AN UNDERSCORE DELIBERATELY. -->. PHP has also attracted the development of many [[Software framework|frameworks]] that provide building blocks and a design structure to promote [[rapid application development]] (RAD). Some of these include [[CakePHP]], [[PRADO]], [[Symfony]] and [[Zend Framework]], offering features similar to other [[List of web application frameworks|web application frameworks]]. The [[LAMP (software bundle)|LAMP]] architecture has become popular in the web industry as a way of deploying web applications. PHP is commonly used as the ''P'' in this bundle alongside [[Linux]], [[Apache HTTP Server|Apache]] and [[MySQL]], although the ''P'' may also refer to [[Python (programming language)|Python]] or [[Perl]]. As of April 2007, over 20 million Internet domains were hosted on servers with PHP installed, and PHP was recorded as the most popular Apache module.<ref name="usage">{{cite web|title=PHP: PHP Usage Stats|url=http://www.php.net/usage.php|publisher=SecuritySpace|accessdate=2008-02-24|date=2007-04-01}}</ref> ==Security== Insecure scripts written in PHP are popular targets of [[Hacker (computer security)|hacker]]s who exploit poorly built applications written in PHP. Software vulnerabilities related to PHP are identified among the [[Common Vulnerabilities and Exposures|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 33.8% for the first quarter of 2008. More than a quarter of all software vulnerabilities listed in this database are related to scripts written in PHP, and more than a third of vulnerabilities listed recently. Most of these vulnerabilities can be exploited remotely, that is without being logged on the computer hosting the vulnerable application.<ref>{{cite web|title=PHP-related vulnerabilities on the National Vulnerability Database|url=http://www.coelho.net/php_cve.html|date=2008-03-01}}</ref> Such exploitation is made possible due to poor programming habits, such as failing to check data before entering it into a database, and features of the language such as <code>register_globals</code>, which is now deprecated.<ref name="register_globals">{{cite web|title=Using Register Globals|url=http://www.php.net/register_globals|accessdate=2008-03-08|date=2008-03-08}}</ref> These result in [[code injection]], [[cross-site scripting]] and other [[application security]] issues. Such attacks are not exclusive to PHP and most can be avoided by following proper coding techniques and principles. ==Syntax== {{main|PHP syntax and semantics}} [[Image:PHP Hello World screenshot.png|frame|right|[[Syntax-highlighted]] PHP code]] PHP only parses code within its [[delimiter]]s. Anything outside its delimiters is sent directly to the output and is not parsed by PHP. The most common delimiters are <code><?php</code> and <code>?></code>, which are open and close delimiters respectively. <code><script language="php"></code> and <code></script></code> delimiters are also available. Short tags (<code><?</code> or <code><?=</code> and <code>?></code>) are also commonly used, but like ASP-style tags (<code><%</code> or <code><%=</code> and <code>%></code>), 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.<ref name="basic syntax">{{cite web|title=PHP: Basic syntax|url=http://www.php.net/manual/en/language.basic-syntax.php|publisher=The PHP Group|accessdate=2008-02-22}}</ref> 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.<ref>{{cite web|accessdate=2008-02-25|url=http://ca3.php.net/manual/en/tutorial.firstpage.php|title=Your first PHP-enabled page |publisher=The PHP Group }}</ref> Variables are prefixed with a [[dollar sign|dollar symbol]] and a [[primitive type|type]] does not need to be specified in advance. Unlike function and class names, variable names are case sensitive. Both double-quoted (<code>""</code>) and [[heredoc]] strings allow the ability to embed a variable's value into the string.<ref>{{cite web|accessdate=2008-03-16|url=http://www.php.net/manual/en/language.variables.php|title=Variables |publisher=The PHP Group }}</ref> PHP treats [[newline]]s as [[whitespace (computer science)|whitespace]] in the manner of a [[free-form language]] (except when inside string quotes), and statements are terminated by a semicolon.<ref>{{cite web|accessdate=2008-03-16|url=http://www.php.net/basic-syntax.instruction-separation|title=Instruction separation |publisher=The PHP Group }}</ref> PHP has three types of [[Comparison of programming languages (syntax)#Comments|comment syntax]]: <code>/* */</code> serves as block comments, and <code>//</code> as well as <code>#</code> are used for inline comments.<ref>{{cite web|accessdate=2008-03-16|url=http://ca3.php.net/manual/en/language.basic-syntax.comments.php|title=Comments |publisher=The PHP Group }}</ref> To output text to the browser, either the <tt>print</tt> function or the <tt>echo</tt> function is used. Both functions are nearly identical; the major difference is that <tt>print</tt> is slower than <tt>echo</tt> because the former will return the integer value of 1 in order to behave more like a function, rather than a [[language construct]], whereas the latter does not return a status and only returns the text for output.<ref>{{cite web|accessdate=2008-03-16|url=http://www.php.net/print|title=print |publisher=The PHP Group }}</ref> Because <tt>print</tt> will behave more like a function, it can be used in expressions where <tt>echo</tt> cannot. It is important to understand however that both are considered language constructs and not functions, the only difference is in their behavior, as outlined above.<ref>{{cite web|accessdate=2008-06-10|url=http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40|title=Differences Between Print And Echo |publisher=php.faqts }}</ref> ===Data types=== PHP stores whole numbers in a platform-dependent range. This range is typically that of 32-bit [[Signed number representations|signed]] [[Integer (computer science)|integer]]s. Unsigned integers are converted to signed values in certain situations; this behavior is different from other programming languages.<ref>{{ cite web | url = http://www.mysqlperformanceblog.com/2007/03/27/integers-in-php-running-with-scissors-and-portability/ | title = Integers in PHP, running with scissors, and portability | date = [[27 March]] [[2007]] | publisher = MySQL Performance Blog | accessdate = 2007-03-28 }}</ref> 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]].<ref name="types">{{cite web|accessdate=2008-03-16|url=http://www.php.net/manual/en/language.types.php|title=Types |publisher=The PHP Group }}</ref> PHP has a native [[Boolean datatype|Boolean]] type that is similar to the native Boolean types in [[Java (programming language)|Java]] and [[C++]]. Using the Boolean type conversion rules, non-zero values are interpreted as true and zero as false, as in Perl and C++.<ref name="types" /> The null data type represents a variable that has no value. The only value in the null data type is ''NULL''.<ref name="types" /> 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.<ref name="types" /> 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 [[Hash table|hashes]] with both keys and values, and the two can be intermingled.<ref name="types" /> PHP also supports [[string (computing)|strings]], which can be used with single quotes, double quotes, or [[heredoc|heredoc syntax]].<ref>{{cite web|accessdate=2008-03-21|url=http://www.php.net/manual/en/language.types.string.php|title=Strings |publisher=The PHP Group }}</ref> ===Functions=== PHP has hundreds of base functions and thousands more from extensions. Functions are not [[first-class function]]s and can only be referenced by their name. <ref name="functions">{{cite web|accessdate=2008-03-16|url=http://www.php.net/manual/en/language.functions.php|title=Functions |publisher=The PHP Group }}</ref> User-defined functions can be created at any time without being prototyped.<ref name="functions" /> Functions can be defined inside code blocks, permitting a [[Dynamic dispatch|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 (computer science)|constructor]] functions called with the PHP <code>new</code> operator, where parentheses are optional. PHP supports quasi-[[anonymous function]]s through the <code>create_function()</code> function, although they are not true anonymous functions because anonymous functions are nameless, but functions can only be referenced by name, or indirectly through a variable <code>$function_name();</code>, in PHP.<ref name="functions" /> ===Objects=== Basic [[object-oriented programming]] functionality was added in PHP 3.<ref name="history" /> Object handling was completely rewritten for PHP 5, expanding the feature set and enhancing performance.<ref name="php 5 objects" /> In previous versions of PHP, objects were handled like [[primitive type]]s.<ref name="php 5 objects">{{cite web|accessdate=2008-03-16|url=http://mjtsai.com/blog/2004/07/15/php-5-object-references/|title=PHP 5 Object References |publisher=mjtsai }}</ref> 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 [[smart pointer#Handles|handle]], and not by value. PHP 5 introduced private and protected [[member variable]]s and methods, along with [[Abstract type|abstract classes]] and [[Final type|final classes]] as well as [[abstract method]]s and [[final method]]s. It also introduced a standard way of declaring [[constructor (computer science)|constructors]] and [[destructor (computer science)|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. [[Object]]s implementing [[ArrayAccess]] can be used with array syntax and [[object]]s implementing [[Iterator]] or [[IteratorAggregate]] can be used with the <code>foreach</code> language construct. There is no [[virtual table]] feature in the engine, so [[static variable]]s are bound with a name instead of a reference at compile time.<ref name="zend engine 2">{{cite web|accessdate=2008-03-16|url=http://www.php.net/zend-engine-2.php|title=Classes and Objects (PHP 5) |publisher=The PHP Group }}</ref> If the developer creates a copy of an object using the reserved word ''clone'', the Zend engine will check if a <tt>__clone()</tt> method has been defined or not. If not, it will call a default <tt>__clone()</tt> which will copy the object's properties. If a <tt>__clone()</tt> 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 [[wikt:replica|replica]] of the source object and only override properties that need to be changed.<ref>{{cite web|accessdate=2008-03-16|url=http://ca3.php.net/language.oop5.cloning|title=Object cloning |publisher=The PHP Group }}</ref> ==Resources== PHP includes [[List of PHP libraries|free and open source libraries]] with the core build. PHP is a fundamentally [[Internet]]-aware system with modules built in for accessing [[File transfer protocol|FTP]] servers, many database servers, embedded SQL libraries such as embedded [[MySQL]] and [[SQLite]], [[Lightweight Directory Access Protocol|LDAP]] servers, and others. Many functions familiar to C programmers such as those in the <tt>[[stdio.h|stdio]]</tt> family are available in the standard PHP build.<ref>{{cite web|accessdate=2008-02-25|url=http://www.php.net/quickref.php|title=PHP Function List |publisher=The PHP Group }}</ref> PHP has traditionally used features such as "[[Magic quotes|magic_quotes_gpc]]" and "magic_quotes_runtime" which attempt to escape apostrophes (') and quotes (") in strings in the assumption that they will be used in databases, to prevent [[SQL injection]] attacks. This leads to confusion over which data is escaped and which is not, and to problems when data is not in fact used as input to a database and when the escaping used is not completely correct.<ref>{{cite web|accessdate=2008-03-25|url=http://news.php.net/php.internals/17883|title=PHP 6.0 Wishlist|publisher=The PHP Group|date=2005-08-12|author=Lerdorf, Rasmus}}</ref> To make code portable between servers which do and do not use magic quotes, developers can preface their code with a script to reverse the effect of magic quotes when it is applied.<ref>{{cite web|url=http://www.php.net/manual/en/security.magicquotes.disabling.php|accessdate=2008-03-25|title=Disabling Magic Quotes|publisher=The PHP Group}}</ref> PHP allows developers to write [[extension (computing)|extensions]] in [[C (programming language)|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 system]]s, multibyte strings ([[Unicode]]), [[cURL]], and several popular [[Archive format|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.<ref>{{cite web|accessdate=2008-02-25|url=http://www.devnewz.com/090902b.html|title=Developing Custom PHP Extensions |publisher=devnewz|date=2002-09-09 }}</ref> As with many scripting languages, PHP scripts are normally kept as human-readable source code, even on production web servers.<ref>{{harv|Gilmore|2006|p=43}}</ref> While this allows flexibility, releasing scripts in source form is undesirable for commercial software developers, and can raise issues with security of web servers; as an example, if a hacker acquires control of a server, database passwords may be quickly discovered, and undesirable changes to scripts may be made that remain undiscovered indefinitely. 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 opportunities for [[optimization (computer science)|code optimization]]<ref>{{cite web|accessdate=2008-03-28|title=PHP Accelerator 1.2 (page 3, Code Optimisation)|url=http://www.php-accelerator.co.uk/PHPA_Article.pdf|publisher=Nick Lindridge }}</ref>, and an example of a code optimizer is the [[PHP accelerator#Zend Optimizer|Zend Optimizer]] PHP extension.<ref>{{cite web|accessdate=2008-03-16|url=http://www.webhostgear.com/184.html|title=Setting Up Zend Optimizer Tutorial |publisher=WebHostGear }}</ref> [[PHP accelerator]]s can offer significant 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. === Certification === [[Zend Technologies|Zend]] provides a [[PHP_Certification|certification]] program for programmers to become certified PHP developers. === PHP vs Python === A detailed comparison of PHP vs Python is given at http://wiki.w4py.org/python-vs-php.html and http://mail.python.org/pipermail/python-list/2004-December/298882.html . ===See also=== {{portal|Free software|Free Software Portal Logo.svg}} * [[Comparison of programming languages]] * [[List of PHP editors]] * [[List of web application frameworks]] * [[PHP accelerator]] * [[Zend Framework]] * [[PHP Certification]] ==Further reading== * {{cite book|title=Programming PHP|author=Lerdorf, Rasmus |date=[[2006-04-28]] |publisher=[[O'Reilly Media]], Inc. |isbn=0596006810 |url=http://www.amazon.com/Programming-PHP-Rasmus-Lerdorf/dp/0596006810 }} ===Notes, links and references=== ===References=== * {{citation|title=Beginning PHP and MySQL 5: From Novice to Professional|last=Gilmore|first= W. Jason |year=2006 |publisher=[[Apress]] |isbn=1590595521 |url=http://www.amazon.com/Beginning-PHP-MySQL-Novice-Professional/dp/1590595521 }} ===External links=== {{Wikibooks|Programming:PHP}} {{Wikiversity}} * [http://www.php.net/ PHP: Hypertext Preprocessor] * {{dmoz|Computers/Programming/Languages/PHP/|PHP}} * [http://www.thelinuxblog.com/linux-man-pages/1/php PHP CLI Man Page] * [http://www.phpsnaps.com/ PHP code snippets] === Notes === {{refs|2<!--3 to dense-->}} {{PHP}} {{FOSS}} [[Category:Curly bracket programming languages]] [[Category:Free compilers and interpreters]] [[Category:Procedural programming languages]] [[Category:Object-oriented programming languages]] [[Category:PHP programming language]] [[Category:Scripting languages]] [[Category:Acronyms]] [[af:PHP]] [[als:PHP]] [[ar:بي.إتش.بي]] [[an:PHP]] [[az:PHP]] [[bn:পিএইচপি]] [[zh-min-nan:PHP]] [[bar:PHP]] [[bs:PHP]] [[br:Areg PHP]] [[bg:PHP]] [[ca:PHP]] [[cs:PHP]] [[cy:PHP]] [[da:PHP]] [[de:PHP]] [[et:PHP]] [[el:PHP]] [[es:PHP]] [[eo:PHP]] [[eu:PHP]] [[fa:زبان برنامه‌نویسی پی‌اچ‌پی]] [[fr:PHP: Hypertext Preprocessor]] [[gl:PHP]] [[ko:PHP]] [[hi:पीएचपी]] [[hr:PHP]] [[id:PHP]] [[is:PHP]] [[it:PHP]] [[he:PHP]] [[ka:PHP]] [[kk:PHP]] [[ku:PHP]] [[la:PHP]] [[lv:PHP]] [[lb:PHP]] [[lt:PHP]] [[hu:PHP]] [[mk:PHP]] [[ml:പി.എച്ച്.പി.]] [[ms:PHP]] [[nl:PHP]] [[ja:PHP: Hypertext Preprocessor]] [[no:PHP]] [[uz:PHP]] [[km:PHP]] [[pl:PHP]] [[pt:PHP]] [[ro:PHP]] [[ru:PHP]] [[sq:PHP]] [[simple:PHP]] [[sk:PHP (programovací jazyk)]] [[sl:PHP]] [[sr:PHP]] [[sh:PHP]] [[fi:PHP]] [[sv:PHP]] [[tl:PHP]] [[th:ภาษาพีเอชพี]] [[vi:PHP]] [[tg:PHP]] [[tr:PHP]] [[uk:PHP]] [[ur:PHP]] [[vls:PHP]] [[zh-yue:PHP]] [[bat-smg:PHP]] [[zh:PHP]]