Old page wikitext, before the edit (old_wikitext ) | '{{Short description|Scripting language created in 1994}}
{{About|the scripting language}}
{{Infobox programming language
| logo = PHP-logo.svg
| file ext = {{codes|.php|.phar|.phtml|.pht|.phps|d=,}}
| paradigm = [[Multi-paradigm programming language|Multi-paradigm]]: [[imperative programming|imperative]], [[functional programming|functional]], [[object-oriented programming|object-oriented]], [[procedural programming|procedural]], [[reflective programming|reflective]]
| released = {{start date and age|1995|06|08|df=y}}<ref name="history-php-release" /><ref name="mysqlconference">{{cite web | last=Lerdorf | first=Rasmus | title=PHP on Hormones – history of PHP presentation by Rasmus Lerdorf given at the MySQL Conference in Santa Clara, California | date=2007-04-26 | access-date=2009-12-11 | publisher=The Conversations Network | url=http://itc.conversationsnetwork.org/shows/detail3298.html | archive-date=2019-01-06 | archive-url=https://web.archive.org/web/20190106230504/http://web.archive.org/web/20130729204354id_/http://itc.conversationsnetwork.org/shows/detail3298.html | url-status=dead }}</ref>
| designer = [[Rasmus Lerdorf]]
| developer = {{URL|https://php.net/credits/|The PHP Development Team}}, [[Zend Technologies]], {{URL|https://thephp.foundation/|PHP Foundation}}
| latest release version = 8.3.4
| latest release date = {{Start date and age|2024|03|14|df=y}}<ref>{{Cite web|url=https://www.php.net/archive/2024.php#2024-03-14-2|title=PHP: News Archive - 2024|website=www.php.net}}</ref>
| latest preview version =
| latest preview date =
| typing = [[Dynamic typing|Dynamic]], [[Strong and weak typing|weak]], [[Gradual typing|gradual]]<ref>{{cite web|url=https://secure.php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration.strict|title=PHP: Function arguments – Manual|website=secure.php.net}}</ref>
| implementations = [[Zend Engine]], [[HHVM]], [[PeachPie]], [[Quercus (software)|Quercus]], [[Parrot virtual machine|Parrot]]
| dialects =
| influenced by = [[Perl]], [[C (programming language)|C]], [[C++]], [[Java (programming language)|Java]],<ref>{{cite web | url = https://www.php.net/manual/en/preface.php | title = PHP: Preface – Manual}}</ref> [[Tcl]],<ref name="mysqlconference" /> [[JavaScript]]<ref name="optimisation ideas">{{Cite tweet |user=dstogov |number=672864802474229760 |last=Stogov |first=Dmitry |date = 2015-12-04 |title=It's not a secret that some #PHP7 optimization ideas came from HHVM, LuaJIT and V8. Thank you @HipHopVM @SaraMG. #php7thankyou}}</ref>
| influenced = [[Hack (programming language)|Hack]], [[Jakarta Server Pages|JSP]], [[Active Server Pages|ASP]], [[React (software)|React JS]]
| programming language = [[C (programming language)|C]] (primarily; some components [[C++]])
| operating system = [[Unix-like]], [[Windows]], [[macOS]], [[IBM i]], [[OpenVMS]]
| license = dual licensed [[GNU General Public License]] version 2 or any later version and PHP License for PHP versions 3.0 or earlier.<ref>{{cite web |title=PHP: Release Archives (museum) |url=https://museum.php.net/php3/ |website=museum.php.net}}</ref> Only [[PHP License]] (most of Zend engine under [[Zend Engine License]]) for 3.01x and later versions.
| website = {{Official URL}}
| wikibooks = PHP Programming
}}
'''PHP''' is a [[general-purpose programming language|general-purpose]] [[scripting language]] geared towards [[web development]].<ref>{{Cite web|url=https://www.php.net/|title=PHP: Hypertext Preprocessor|website=www.php.net|access-date=2020-02-12}}</ref> It was originally created by Danish-Canadian [[programmer]] [[Rasmus Lerdorf]] in 1993 and released in 1995.<ref name=":0">{{Cite web |last=Krill |first=Paul |date=2013-11-18 |title=Believe the hype: PHP founder backs Facebook's HipHop technology |url=https://www.infoworld.com/article/2609877/believe-the-hype--php-founder-backs-facebook-s-hiphop-technology.html |access-date=2022-10-13 |website=InfoWorld |language=en}}</ref><ref>{{Cite web |title=Announce: Personal Home Page Tools (PHP Tools) |url=https://groups.google.com/g/comp.infosystems.www.authoring.cgi/c/PyJ25gZ6z7A/m/M9FkTUVDfcwJ?pli=1 |access-date=2022-11-03 |website=groups.google.com}}</ref> The PHP [[reference implementation]] is now produced by the PHP Group.<ref name="about PHP">{{cite web|access-date=2008-02-25|url=https://www.php.net/history|title=History of PHP and related projects |publisher=The PHP Group}}</ref> PHP was originally an abbreviation of '''''Personal Home Page''''',<ref name="History of PHP">{{cite web |title=History of PHP |url=https://php.net/manual/en/history.php.php |website=php.net}}</ref><ref>{{Cite book |last=Olsson |first=Mikael |url=https://books.google.com/books?id=_ahBAAAAQBAJ |title=PHP Quick Scripting Reference |date=2013-09-04 |publisher=Apress |isbn=978-1-4302-6284-8 |language=en}}</ref> but it now stands for the [[recursive initialism]] '''''PHP: Hypertext Preprocessor'''''.<ref>[https://php.net/manual/en/preface.php PHP Manual: Preface], www.php.net.</ref>
PHP code is usually processed on a [[web server]] by a PHP [[interpreter (computing)|interpreter]] implemented as a [[plugin (computing)|module]], a [[daemon (computing)|daemon]] or a [[Common Gateway Interface]] (CGI) executable. On a web server, the result of the [[interpreter (computing)|interpreted]] and executed PHP code{{em dash}}which may be any type of data, such as generated [[HTML]] or [[binary number|binary]] image data{{em dash}}would form the whole or part of an [[HTTP]] response. Various [[web template system]]s, web [[content management system]]s, and [[web framework]]s exist that can be employed to orchestrate or facilitate the generation of that response. Additionally, PHP can be used for many programming tasks outside the web context, such as standalone [[graphical user interface|graphical applications]]<ref>{{cite web | url = https://php.net/manual/en/intro-whatcando.php | work = PHP Manual | title = Introduction: What can PHP do? | access-date = 2009-03-05}}</ref> and [[unmanned aerial vehicle|drone]] control.<ref>{{Citation|title=helicopter: Port of node-ar-drone which allows user to control a Parrot AR Drone over PHP: jolicode/php-ar-drone|date=2019-01-11|url=https://github.com/jolicode/php-ar-drone|publisher=JoliCode|access-date=2019-02-23}}</ref> PHP code can also be directly executed from the [[command-line interface|command line]].
The standard PHP interpreter, powered by the [[Zend Engine]], is [[free software]] released under the [[PHP License]]. PHP has been widely ported and can be deployed on most web servers on a variety of [[operating system]]s and [[computing platform|platforms]].<ref name="foundations" />
The PHP language has evolved without a written [[formal specification]] or standard<!-- until 2014-->, with the original [[implementation]] acting as the ''[[de facto]]'' standard that other implementations aimed to follow. <!-- PHP standard spec dropped at Github, besides would have been on old EOLed version of PHP: Since 2014, work has gone on to create a formal PHP specification.<ref>{{cite web|last1=Jackson|first1=Joab|title=PHP gets a formal specification, at last|url=https://www.computerworld.com/article/2490649/php-gets-a-formal-specification--at-last.html|website=Computerworld|publisher=[[International Data Group|IDG]]|date=2014-07-31}}</ref> -->
W3Techs reports that {{as of|2024|03|23|lc=y}} (the four months after the PHP 8.3 release), PHP is used by 76.4% of all websites whose programming language could be determined, and 57.2% thereof use PHP 7 which is outdated and known to be insecure.<ref name="PHP Usage Stats" /> Additionally, <!-- the most used version of 8.x, --> PHP 8.0, is no longer supported,<ref>{{Cite web |title=Usage Statistics and Market Share of PHP Version 8 for Websites, March 2024 |url=https://w3techs.com/technologies/details/pl-php/8 |access-date=2024-03-23 |website=w3techs.com}}</ref> meaning the vast majority of PHP users utilize outdated versions, and well over half of all websites, PHP-using or not (whose programming language could be determined) are insecure.<!-- this part detailed described in "Security" section, may be is better to remove it from here -->
== History ==
{{multiple image
| align = right
| width = 105
| image1 = Rasmus Lerdorf cropped.jpg
| image2 = Andi Gutmans 1.jpg
| image3 = Zeev Suraski 2005 cropped.jpg
| footer = [[Rasmus Lerdorf]], creator of PHP; and [[Andi Gutmans]] and [[Zeev Suraski]], creators of the [[Zend Engine]]
}}
=== Early history ===
PHP development began in 1993<ref name=":0" /> when [[Rasmus Lerdorf]] wrote several [[Common Gateway Interface]] (CGI) programs in [[C-programming|C]],<ref name="php_origins">{{cite web | url = https://twitter.com/rasmus/status/226405807305138176 | title = I wonder why people keep writing that PHP was ever written in Perl. It never was. #php | last = Lerdorf | first = Rasmus | publisher = Twitter | date = 2012-07-20 | access-date = 2014-09-04}}</ref><ref>{{cite web | url = http://itc.conversationsnetwork.org/shows/detail3298.html | title = PHP on Hormones | format = mp3 | last = Lerdorf | first = Rasmus | publisher = The Conversations Network | date = 2007-04-26 | access-date = 2009-06-22 | archive-date = 2019-01-06 | archive-url = https://web.archive.org/web/20190106230504/http://web.archive.org/web/20130729204354id_/http://itc.conversationsnetwork.org/shows/detail3298.html | url-status = dead }}</ref> which he used to maintain his [[personal homepage]]. He extended them to work with [[web form]]s and to communicate with [[database]]s, and called this implementation "Personal Home Page/Forms Interpreter" or PHP/FI.
An example of the early PHP [[Syntax (programming languages)|syntax]]:<ref>{{cite web|last=Lerdorf|first=Rasmus|year=2007|title=Slide 3|url=http://talks.php.net/show/mysql07key/3|access-date=2009-06-22|work=slides for 'PHP on Hormones' talk|publisher=The PHP Group}}
</ref>
<syntaxhighlight lang="PHP">
<!--include /text/header.html-->
<!--getenv HTTP_USER_AGENT-->
<!--if substr $exec_result Mozilla-->
Hey, you are using Netscape!<p>
<!--endif-->
<!--sql database select * from table where user='$username'-->
<!--ifless $numentries 1-->
Sorry, that record does not exist<p>
<!--endif exit-->
Welcome <!--$user-->!<p>
You have <!--$index:0--> credits left in your account.<p>
<!--include /text/footer.html-->
</syntaxhighlight>
PHP/FI could be used to build simple, [[dynamic web application]]s. To accelerate [[software bug|bug]] reporting and improve the code, Lerdorf initially announced the release of PHP/FI as "Personal Home Page Tools (PHP Tools) version 1.0" on the [[Usenet]] discussion group ''comp.infosystems.www.authoring.cgi'' on 8 June 1995.<ref name="history-php-release">{{cite web|url= https://groups.google.com/group/comp.infosystems.www.authoring.cgi/msg/cc7d43454d64d133?pli=1 |title=Announce: Personal Home Page Tools (PHP Tools)|last=Lerdorf|first=Rasmus|date=June 8, 1995|access-date=7 June 2011}}</ref><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 = https://groups.google.com/group/comp.infosystems.www.authoring.cgi/msg/cc7d43454d64d133 | access-date = 2006-09-17}}</ref> This release included basic functionality such as [[Local variable#Local variables in Perl|Perl-like variables]], form handling, and the ability to embed [[HTML]]. By this point, the [[syntax]] had changed to resemble that of [[Perl]], but was simpler, more limited, and less consistent.<ref name="History of PHP" /><ref name="about PHP" />
Early PHP was never intended to be a new [[Programming language theory|programming language]]; rather, it grew organically, with Lerdorf noting in retrospect: "I don't know how to stop it [...] there was never any intent to write a programming language [...] I have absolutely no idea how to write a programming language [...] I just kept adding the next logical step on the way."<ref name=itconversations>{{cite web|title = Rasmus Lerdorf, Senior Technical Yahoo: PHP, Behind the Mic|date = 2003-11-19|url =http://itc.conversationsnetwork.org/shows/detail58.html|archive-url = https://web.archive.org/web/20130728125152/http://itc.conversationsnetwork.org/shows/detail58.html|archive-date = 2013-07-28}}</ref> A development team began to form and, after months of work and [[Beta development stage|beta]] testing, officially released PHP/FI 2 in November 1997<ref>{{Cite web |last1=Alshetwi |first1=A.B. |last2=Rahmat |first2=R. A. A. O. |last3=Borhan |first3=M. N. |last4=Ismael |first4=S. |last5=Ali |first5=A. |last6=Irtema |first6=H. I. M. |last7=Alfakhria |first7=A. Y. |date=2018 |title=Web-Based Expert System for Optimizing of Traffic Road in Developing Countries |url=https://www.researchgate.net/publication/326727672 |access-date=13 Feb 2024}}</ref>.{{Citation needed|date=November 2023}}
The fact that PHP was not originally designed, but instead was developed organically has led to inconsistent naming of functions and inconsistent ordering of their parameters.<ref>{{cite web|title=Problems with PHP|url=http://toykeeper.net/soapbox/php_problems/|access-date=20 December 2010}}</ref> In some cases, the function names were chosen to match the lower-level libraries which PHP was "wrapping",<ref>{{cite web|url=http://news.php.net/php.internals/70950 |title=php.internals: Re: Function name consistency |website=news.php.net |date=2013-12-28 |access-date=2014-02-09}}</ref> while in some very early versions of PHP the length of the function names was used internally as a [[hash function]], so names were chosen to improve the distribution of [[hash values]].<ref name="php-internals-70691">{{cite newsgroup |title=Re: Flexible function naming |author=[[Rasmus Lerdorf]] |date=Dec 16, 2013 |newsgroup=php.internals |url=http://news.php.net/php.internals/70691 |access-date=December 26, 2013}}</ref>
=== PHP 3 and 4 ===
[[File:Custom-software-developement-php-net.JPG|thumb|This is an example of PHP code for the [[WordPress]] [[content management system]].]]
[[Zeev Suraski]] and [[Andi Gutmans]] rewrote the [[parser]] in 1997 and formed the base of PHP 3, changing the language's name to the [[recursive acronym]] ''PHP: Hypertext Preprocessor''.<ref name="about PHP" /><ref>{{cite web|title=PHP{{snd}} Acronym Meaning Vote |url=http://il.php.net/vote_listing.php3 |website=PHP.net |archive-date=August 15, 2000 |url-status=dead |archive-url=https://web.archive.org/web/20000815063125/http://il.php.net/vote_listing.php3}}</ref> 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 | access-date = 2006-09-17 | archive-url = https://web.archive.org/web/20060719204721/http://www.zend.com/zend/zend-engine-summary.php | archive-date = 2006-07-19 | url-status = dead}}</ref> They also founded [[Zend Technologies]] in [[Ramat Gan]], [[Israel]].<ref name="about PHP" />
On 22 May 2000, PHP 4, powered by the Zend Engine 1.0, was released.<ref name="about PHP" /> By August 2008, this branch had reached version 4.4.9. PHP 4 is now no longer under development and nor are any security updates planned to be released.<ref name="2007 news">{{cite web|title=php.net 2007 news archive|url=https://www.php.net/archive/2007.php|publisher=The PHP Group|access-date=2008-02-22|date=2007-07-13}}</ref><ref>{{cite web |access-date=2018-12-16 |url=https://www.internetnews.com/developer/php-4-is-dead%ef%bf%bdlong-live-php-5/|title=PHP 4 is Dead—Long Live PHP 5 |publisher=InternetNews |date=2008-02-01 |last=Kerner |first=Sean Michael |archive-url=https://web.archive.org/web/20180806115411/http://www.internetnews.com/dev-news/article.php/3725291 |archive-date=2018-08-06}}</ref>
=== PHP 5 ===
On 1 July 2004, PHP 5 was released, powered by the new Zend Engine II.<ref name="about PHP" /> PHP 5 included new features such as improved support for [[object-oriented programming]], the PHP Data Objects (PDO) 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|access-date=2008-02-22|date=2004-07-15|author=Trachtenberg, Adam|archive-date=2016-03-31|archive-url=https://web.archive.org/web/20160331232050/http://www.onlamp.com/pub/a/php/2004/07/15/UpgradePHP5.html|url-status=dead}}</ref> In 2008, PHP 5 became the only stable version under development. [[Late static binding]] had been missing from previous versions of PHP, and was added in version 5.3.<ref>{{cite web|url=http://www.digitalsandwich.com/archives/53-Late-Static-Binding-in-PHP.html|access-date=2008-03-25|title=Late Static Binding in PHP|date=2006-02-23|publisher=Digital Sandwich}}</ref><ref>{{cite web|access-date=2008-03-25|url=https://www.php.net/language.oop5.static|title=Static Keyword|publisher=The PHP Group}}</ref>
Many high-profile open-source projects ceased to support PHP 4 in new code from February 5, 2008, because of the GoPHP5 initiative,<ref name="gophp5_projects">{{cite web | url=http://www.gophp5.org/projects|title=GoPHP5 | url-status=dead | archive-url=https://web.archive.org/web/20110717133313/http://gophp5.org/projects | archive-date=2011-07-17}}</ref> 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 |access-date=2008-02-23 |work=GoPHP5 Press Release | url-status=dead | archive-url=https://web.archive.org/web/20190804012720/http://gophp5.org/sites/gophp5.org/files/press_release.pdf | archive-date=2019-08-04}}</ref><ref>{{cite web|url=http://gophp5.org/|title=GoPHP5|publisher=GoPHP5|access-date=2008-02-22 | url-status=dead | archive-url=https://web.archive.org/web/20110427101913/http://www.gophp5.org/ | archive-date=2011-04-27}}</ref>
Over time, PHP interpreters became available on most existing [[32-bit]] and [[64-bit]] operating systems, either by building them from the PHP source code or by using pre-built binaries.<ref>{{cite web
| url = https://www.php.net/manual/en/install.php
| title = PHP Installation and Configuration
| access-date = 2013-10-29
| website = php.net
}}</ref> For PHP versions 5.3 and 5.4, the only available [[Microsoft Windows]] binary distributions were 32-bit [[IA-32]] builds,<ref>{{cite web
| url = https://windows.php.net/download/#php-5.3
| title = PHP for Windows: Binaries and sources releases (5.3)
| access-date = 2013-10-29
| website = php.net
}}</ref><ref>{{cite web
| url = https://windows.php.net/download/#php-5.4
| title = PHP for Windows: Binaries and sources releases (5.4)
| access-date = 2013-10-29
| website = php.net
}}</ref> requiring Windows 32-bit compatibility mode while using [[Internet Information Services]] (IIS) on a 64-bit Windows platform. PHP version 5.5 made the 64-bit [[x86-64]] builds available for Microsoft Windows.<ref>{{cite web
| url = https://windows.php.net/download/#php-5.5
| title = PHP for Windows: Binaries and sources releases (5.5)
| access-date = 2013-10-29
| website = php.net
}}</ref>
Official security support for PHP 5.6 ended on 31 December 2018.<ref>{{Cite web | url=https://php.net/supported-versions.php |title = PHP: Supported Versions}}</ref>
=== <span id="PHP6-UNICODE">PHP 6 and Unicode</span> ===
PHP received mixed reviews due to lacking native [[Unicode]] support at the core language level.<ref>{{cite web
| url = https://php.net/manual/en/language.types.string.php
| title = Types: Strings (PHP Manual)
| access-date = 2013-09-22
| website = PHP.net
}}</ref><ref>{{cite web
| url = https://www.php.net/manual/en/language.types.string.php#language.types.string.details
| title = Details of the String Type (PHP Manual)
| access-date = 2021-09-22
| website = PHP.net
}}</ref> In 2005, a project headed by Andrei Zmievski was initiated to bring native [[Unicode]] support throughout PHP, by embedding the [[International Components for Unicode]] (ICU) library, and representing text strings as [[UTF-16]] internally.<ref>{{cite mailing list|url=http://marc.info/?l=php-internals&m=112365908921757&w=1|title=PHP Unicode support design document|date=2005-08-10|access-date=2014-02-09|author=Andrei Zmievski}}</ref> Since this would cause major changes both to the internals of the language and to user code, it was planned to release this as version 6.0 of the language, along with other major features then in development.<ref>{{cite web|url=http://news.php.net/php.internals/17668|title=PHP 5.5 or 6.0|access-date=2014-02-09}}</ref>
However, a shortage of developers who understood the necessary changes, and performance problems arising from conversion to and from UTF-16, which is rarely used in a web context, led to delays in the project.<ref>{{cite web|title=The Good, the Bad, and the Ugly: What Happened to Unicode and PHP 6|url=http://www.slideshare.net/andreizm/the-good-the-bad-and-the-ugly-what-happened-to-unicode-and-php-6|access-date=2014-02-09|author=Andrei Zmievski|date=2011-04-22}}</ref> As a result, a PHP 5.3 release was created in 2009, with many non-Unicode features back-ported from PHP 6, notably namespaces. In March 2010, the project in its current form was officially abandoned, and a PHP 5.4 release was prepared to contain most remaining non-Unicode features from PHP 6, such as traits and closure re-binding.<ref>{{cite mailing list|url=http://news.php.net/php.internals/47120|title=PHP 6|access-date=2014-02-07|date=2010-03-11|author=Rasmus Lerdorf}}</ref> Initial hopes were that a new plan would be formed for Unicode integration, but by 2014 none had been adopted.{{Citation needed|date=November 2023}}
=== PHP 7 ===
During 2014 and 2015, a new major PHP version was developed, PHP 7. The numbering of this version involved some debate among internal developers.<ref>{{cite web|url=https://philsturgeon.uk/php/2014/07/23/neverending-muppet-debate-of-php-6-v-php-7/|title=The Neverending Muppet Debate of PHP 6 v PHP 7|access-date=2015-11-19|archive-url=https://web.archive.org/web/20151119132438/https://philsturgeon.uk/php/2014/07/23/neverending-muppet-debate-of-php-6-v-php-7/|archive-date=2015-11-19|url-status=dead}}</ref> While the PHP 6 Unicode experiments had never been released, several articles and book titles referenced the PHP 6 names, which might have caused confusion if a new release were to reuse the name.<ref>{{cite web |title=RFC: Name of Next Release of PHP |url=https://wiki.php.net/rfc/php6 |date=2014-07-07 |access-date=2014-07-15 |website=php.net}}</ref> After a vote, the name PHP 7 was chosen.<ref>{{cite web|title=Re: [PHP-DEV] [VOTE] [RFC] Name of Next Release of PHP (again) |url=https://www.mail-archive.com/internals@lists.php.net/msg68598.html |date=2014-07-30 |access-date=2014-07-30}}</ref>
The foundation of PHP 7 is a PHP [[branching (version control)|branch]] that was originally dubbed ''PHP next generation'' (''phpng''). It was authored by Dmitry Stogov, Xinchen Hui and Nikita Popov,<ref>{{cite web|url=http://news.php.net/php.internals/73888|title=phpng: Refactored PHP Engine with Big Performance Improvement|website=news.php.net}}</ref> and aimed to optimize PHP performance by refactoring the Zend Engine while retaining near-complete language compatibility.<ref>{{cite web |url=https://wiki.php.net/rfc/phpng |title=PHP: rfc:phpng |access-date=16 December 2014 |website=php.net}}</ref> By 14 July 2014, [[WordPress]]-based benchmarks, which served as the main benchmark suite for the phpng project, showed an almost 100% increase in performance. Changes from phpng make it easier to improve performance in future versions, as more compact data structures and other changes are seen as better suited for a successful migration to a [[Just-in-time compilation|just-in-time]] (JIT) compiler.<ref name="phpng">{{cite web|url=https://wiki.php.net/phpng |title=PHP: phpng |website=php.net |access-date=2014-07-15}}</ref> Because of the significant changes, the reworked Zend Engine was called ''Zend Engine 3'', succeeding Zend Engine 2 used in PHP 5.<ref name="ZE2">{{cite web |url=https://github.com/php/php-src/commit/150dc69d6eee35738f505e925ee664c02060196d |website=github.com |date=2014-12-05 |access-date=2014-12-05 |title=Merge branch 'ZendEngine3'}}</ref>
Because of the major internal changes in phpng, it must receive a new [[Software versioning|major version]] number of PHP, rather than a minor PHP 5 release, according to PHP's release process.<ref name="releaseprocess" /> Major versions of PHP are allowed to break backward-compatibility of code and therefore PHP 7 presented an opportunity for other improvements beyond phpng that require backward-compatibility breaks.{{Citation needed|date=November 2023}} In particular, it involved the following changes:
* Many fatal or recoverable-level legacy PHP error mechanisms were replaced with modern object-oriented [[Exception (computer science)|exceptions]].<ref name="engine_exceptions" />
* The syntax for variable dereferencing was reworked to be internally more consistent and complete, allowing the use of the operators <code>-></code>, <code>[]</code>, <code>()</code>,<code>{}</code>, and <code>::</code>, with arbitrary meaningful left-side expressions.<ref name="uvs">{{cite web |url=https://wiki.php.net/rfc/uniform_variable_syntax |title=PHP RFC: Uniform Variable Syntax |date=2014-05-31 |access-date=2014-07-30 |website=php.net}}</ref>
* Support for legacy PHP 4-style constructor methods was deprecated.<ref>{{Cite web|url=https://3v4l.org/udRhX|title=Online PHP editor | output for udRhX|website=3v4l.org}}</ref>
* The behavior of the [[foreach loop|<code>foreach</code> statement]] was changed to be more predictable.<ref>{{cite web|url=https://wiki.php.net/rfc/php7_foreach|title=PHP RFC: Fix "foreach" behavior|access-date=2015-05-21|website=php.net}}</ref>
* Constructors for the few classes built-in to PHP which returned null upon failure were changed to throw an exception instead, for consistency.<ref>{{cite web|url=https://wiki.php.net/rfc/internal_constructor_behaviour|title=PHP RFC: Constructor behaviour of internal classes|access-date=2015-05-21|website=php.net}}</ref>
* Several unmaintained or deprecated [[server application programming interface]]s (SAPIs) and extensions were removed from the PHP core, most notably the legacy <code>mysql</code> extension.<ref>{{cite web|url=https://wiki.php.net/rfc/removal_of_dead_sapis_and_exts|title=PHP RFC: Removal of dead or not yet PHP7 ported SAPIs and extensions|access-date=2015-05-21|website=php.net}}</ref>
* The behavior of the <code>list()</code> operator was changed to remove support for strings.<ref>{{cite web|url=https://wiki.php.net/rfc/fix_list_behavior_inconsistency|title=PHP RFC: Fix list() behavior inconsistency|access-date=2015-05-21|website=php.net}}</ref>
* Support was removed for legacy ASP-style delimiters <code><%</code> and <code>%></code> and <code><script language="php"> ... </script></code>.<ref>{{cite web|url=https://wiki.php.net/rfc/remove_alternative_php_tags|title=PHP RFC: Remove alternative PHP tags|access-date=2015-05-21|website=php.net}}</ref>
* An oversight allowing a [[switch statement]] to have multiple <code>default</code> clauses was fixed.<ref>{{cite web|url=https://wiki.php.net/rfc/switch.default.multiple|title=PHP RFC: Make defining multiple default cases in a switch a syntax error|access-date=2015-05-21|website=php.net}}</ref>
* Support for hexadecimal number support in some implicit conversions from strings to number types was removed.<ref>{{cite web|url=https://wiki.php.net/rfc/remove_hex_support_in_numeric_strings|title=PHP RFC: Remove hex support in numeric strings|access-date=2015-05-21|website=php.net}}</ref>
* The [[left-shift operator|left-shift]] and [[right-shift operator|right-shift]] operators were changed to behave more consistently across platforms.<ref name="integer_semantics" />
* Conversions between floating-point numbers and integers were changed (e.g. infinity changed to convert to zero) and implemented more consistently across platforms.<ref name="integer_semantics">{{cite web|url=https://wiki.php.net/rfc/integer_semantics|title=PHP RFC: Integer Semantics|access-date=2015-05-21|quote=Making NaN and Infinity always become zero when cast to integer means more cross-platform consistency, and is also less surprising than what is currently produces|website=php.net}}</ref><ref>{{cite web|url=https://wiki.php.net/rfc/zpp_fail_on_overflow|title=PHP RFC: ZPP Failure on Overflow|access-date=2015-05-21|website=php.net}}</ref>
PHP 7 also included new language features. Most notably, it introduced return type declarations for functions<ref name="return-types">{{cite web |url=https://wiki.php.net/rfc/return_types |title=RFC: Return Types |date=2015-01-27 |access-date=2015-01-28 |website=php.net}}</ref> which complement the existing parameter type declarations, and support for the [[Variable (computer science)|scalar]] types (integer, float, string, and boolean) in parameter and return type declarations.<ref name="scalar-types">{{cite web|url=https://wiki.php.net/rfc/scalar_type_hints_v5|title=RFC: Scalar Type Declarations |date=2015-03-16 |access-date=2015-03-17 |website=php.net}}</ref>
=== PHP 8 ===
PHP 8 was released on 26 November 2020, and is currently the second-most used PHP major version. PHP 8 is a major version and has breaking changes from previous versions.<ref name="new-in-php8">{{cite web |author=Brent |title=What's new in PHP 8 |url=https://stitcher.io/blog/new-in-php-8 |website=Stitcher |access-date=22 September 2020}}</ref><ref name="PHP-8-Released">{{cite web |title=PHP 8 Released|url=https://www.php.net/releases/8.0/en.php |website=PHP |access-date=27 November 2020}}</ref> New features and notable changes include:
==== Just-in-time compilation ====
[[Just-in-time compilation]] is supported in PHP 8.<ref name="php-8-JIT" />
PHP 8's [[just-in-time compilation|JIT compiler]] can provide substantial performance improvements for some use cases,<ref name="php-jit-performance-in-web-apps">{{cite web |author=Brent |title=PHP 8: JIT performance in real-life web applications |url=https://stitcher.io/blog/jit-in-real-life-web-applications |website=Stitcher.io |access-date=4 October 2020}}</ref><ref>{{cite web |last1=Rethams |first1=Derick |title=PHP 8: A Quick Look at JIT |url=https://derickrethans.nl/a-quick-look-at-jit.html}}</ref> while PHP developer Nikita Popov stated that the performance improvements for most websites will be less substantial than the upgrade from PHP 5 to PHP 7.<ref name="php-8-nikita-popov" /> Substantial improvements are expected more for mathematical-type operations than for common web-development use cases.<ref name="php-8-nikita-popov">{{cite web |last1=Popov |first1=Nikita |title="What's new in PHP 8.0?" Nikita Popov |url=https://www.youtube.com/watch?v=NbBRXwu1Md8 |archive-url=https://ghostarchive.org/varchive/youtube/20211211/NbBRXwu1Md8| archive-date=2021-12-11 |url-status=live|publisher=PHP fwdays |access-date=4 October 2020}}{{cbignore}}</ref> Additionally, the JIT compiler provides the future potential to move some code from C to PHP, due to the performance improvements for some use cases.<ref name="kinsta-php-8-changes">{{cite web |last1=Daniele |first1=Carlo |title=What's New in PHP 8 (Features, Improvements, and the JIT Compiler) |url=https://kinsta.com/blog/php-8/ |website=Kinsta |date=25 May 2020 |access-date=24 December 2020}}</ref>
==== Addition of the match expression ====
{{Main|PHP syntax and semantics#Match expression}}
PHP 8 introduced the {{code|match}} expression.<ref name="match-statement-php-8-laravel-news">{{cite web |last1=Redmond |first1=Paul |title=Match Expression is Coming to PHP 8 |url=https://laravel-news.com/match-expression-php-8 |website=Laravel News |date=15 July 2020 |access-date=4 October 2020}}</ref> The match expression is conceptually similar to a {{code|switch}} statement and is more compact for some use cases.<ref name="php-watch-match-statements-php-8">{{cite web |title=PHP 8.0: Match Expressions |url=https://php.watch/versions/8.0/match-expression |website=PHP Watch |access-date=4 October 2020}}</ref> Because {{code|match}} is an expression, its result can be assigned to a variable or returned from a function.<ref>{{cite web |last1=Barnes |first1=Eric |title=PHP 8 is now Released! |url=https://laravel-news.com/php-8 |website=Laravel News |date=27 November 2020 |access-date=24 December 2020 |ref=laravel-news-php-8-released}}</ref>
==== Type changes and additions ====
PHP 8 introduced union types, a new {{code|static}} return type, and a new {{code|mixed}} type.<ref name="new-in-php8" />
"Attributes", often referred to as "annotations" in other programming languages, were added in PHP 8, which allow metadata to be added to classes.<ref name="new-in-php8" />
{{code|throw}} was changed from being a statement to being an expression.<ref name="throw-expression-php8" /> This allows exceptions to be thrown in places that were not previously possible.<ref name="new-in-php8" />
==== Syntax changes and additions ====
PHP 8 includes changes to allow alternate, more concise, or more consistent syntaxes in a number of scenarios. For example, the nullsafe operator is similar to the [[null coalescing operator]] {{code|??}}, but used when calling methods.<ref name="nullsafe-operator-rfc" /> The following code snippet will not throw an error if {{code|getBirthday()}} returns null:
<syntaxhighlight lang="php">
$human_readable_date = $user->getBirthday()?->diffForHumans();
</syntaxhighlight>
Constructor property promotion has been added as "[[syntactic sugar]]," allowing class properties to be set automatically when parameters are passed into a class [[Constructor (object-oriented programming)|constructor]].<ref name="new-in-php8" /> This reduces the amount of [[boilerplate code]] that must be written.{{Citation needed|date=November 2023}}
Other minor changes include support for use of {{code|::class}} on objects, which serves as an alternative for the use of {{code|get_class()}};<ref name="new-in-php8" /> non-capturing catches in try-catch blocks; variable syntax tweaks to resolve inconsistencies; support for named arguments; and support for trailing commas in parameter lists, which adds consistency with support for trailing commas in other contexts, such as in arrays.{{Citation needed|date=November 2023}}
==== Standard library changes and additions ====
* Weak maps were added in PHP 8. A {{code|WeakMap}} holds references to objects, but these references do not prevent such objects from being [[Garbage collection (computer science)|garbage collected]].<ref name="php-8-weak-refs" /> This can provide performance improvements in scenarios where data is being [[Cache (computing)|cached]]; this is of particular relevance for [[object–relational mapping]]s (ORM).<ref name="new-in-php8" />
* Various adjustments to interfaces, such as adding support for creating {{code|DateTime}} objects from interfaces, and the addition of a {{code|Stringable}} interface that can be used for type hinting.{{Citation needed|date=November 2023}}
* Various new functions including str_contains(), str_starts_with(), and str_ends_with();<ref name="new-string-functions-php-8">{{cite web |last1=Merchant |first1=Amit |title=These new string functions are coming in PHP 8 |url=https://www.amitmerchant.com/new-string-functions-php8/ |website=Amit Merchant |date=13 June 2020 |access-date=4 October 2020}}</ref> fdiv(); get_debug_type(); and get_resource_id(){{Citation needed|date=November 2023}}
* Object implementation of token_get_all(){{Citation needed|date=November 2023}}
==== Additional changes ====
* Type annotations were also added into PHP's C source code itself to allow internal functions and methods to have "complete type information in reflection."<ref>{{cite web |last1=Popov |first1=Nikita |title=Call for participation: Annotating internal function argument and return types |url=https://externals.io/message/106522 |website=Externals |access-date=19 November 2020}}</ref>
* Inheritance with private methods{{Citation needed|date=November 2023}}
* Abstract methods in traits improvements{{Citation needed|date=November 2023}}
=== PHP 8.1 ===
PHP 8.1 was released on November 25, 2021.<ref>{{Cite web|url=https://www.php.net/ChangeLog-8.php#8.1.0 |title=PHP 8 ChangeLog |access-date=2024-01-05 |website=PHP.net}}</ref> It added support for [[enumerated type|enumerations]] (also called "enums"), declaring properties as <code>readonly</code> (which prevents modification of the property after initialization), and array unpacking with string keys. The new [[bottom type|never type]] can be used to indicate that a function does not return.<ref>{{Cite web|title=PHP: PHP 8.1.0 Release Announcement |url=https://www.php.net/releases/8.1/en.php |access-date=2024-01-05 |website=PHP.net}}</ref>
=== PHP 8.2 ===
PHP 8.2 was released on December 8, 2022.<ref>{{Cite web|url=https://www.php.net/ChangeLog-8.php#8.2.0 |title=PHP 8 ChangeLog |access-date=2024-01-05 |website=PHP.net}}</ref> New in this release are <code>readonly</code> classes (whose instance properties are implicitly readonly), [[disjunctive normal form]] (DNF) types, and the <code>random</code> extension, which provides a [[pseudorandom number generator]] with an object-oriented [[API]].<ref>{{Cite web|title=PHP: PHP 8.2.0 Release Announcement |url=https://www.php.net/releases/8.2/en.php |access-date=2024-01-05 |website=PHP.net}}</ref>
=== Release history ===
<!-- Template:Version - for version & release history. Documentation and examples: http://en.wikipedia.org/wiki/Template:Version -->
{| class="wikitable
|-
! Version
! style="min-width: 10em;" | Release date
! style="min-width: 10em;" | Supported until<ref name="eol">{{cite web|url=https://php.net/eol.php |title=Unsupported Branches |website=php.net |access-date=2019-07-31}}</ref>
! Notes
|-
| {{Version |o | 1.0}}
| 8 June 1995
|
| Officially called "Personal Home Page Tools (PHP Tools)". This is the first use of the name "PHP".<ref name="about PHP" />
|-
| {{Version |o | 2.0}}
| 1 November 1997
|
| Officially called "PHP/FI 2.0". This is the first release that could actually be characterised as PHP, being a standalone language with many features that have endured to the present day.
|-
| {{Version |o | 3.0}}
| 6 June 1998
| 20 October 2000<ref name="eol" />
| Development moves from one person to multiple developers. Zeev Suraski and Andi Gutmans rewritten the base for this version.<ref name="about PHP" />
|-
| {{Version |o | 4.0}}
| 22 May 2000<ref>{{cite web |title=PHP 4.0.0 Released |url=https://news-web.php.net/php.announce/22 |access-date=25 October 2020}}</ref>
| 23 June 2001<ref name="eol" />
| 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=https://www.php.net/ChangeLog-4.php|publisher=The PHP Group|access-date=2008-02-22|date=2008-01-03}}</ref>
|-
| {{Version |o | 4.1}}
| 10 December 2001<ref>{{cite web |title=PHP 4.1.0 Release Announcement |url=https://www.php.net/releases/4_1_0.php |access-date=25 October 2020}}</ref>
| 12 March 2002<ref name="eol" />
| Introduced "superglobals" ({{code|lang=php|$_GET}}, {{code|lang=php|code=$_POST}}, {{code|lang=php|code=$_SESSION}}, etc.)<ref name="php4changelog" />
|-
| {{Version |o | 4.2}}
| 22 April 2002<ref>{{cite web |title=PHP 4.2.0 Release Announcement |url=https://www.php.net/releases/4_2_0.php |access-date=25 October 2020}}</ref>
| 6 September 2002<ref name="eol" />
| Disabled <code>register_globals</code> 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" />
|-
| {{Version |o | 4.3}}
| 27 December 2002<ref>{{cite web |title=PHP 4.3.0 Release Announcement |url=https://www.php.net/releases/4_3_0.php |access-date=25 October 2020}}</ref>
| 31 March 2005<ref name="eol" />
| Introduced the [[command-line interface]] (CLI), to supplement the CGI.<ref name="php4changelog" /><ref name="phpclidocs">{{cite web|title= Using PHP from the command line | work = PHP Manual|url=https://php.net/manual/en/features.commandline.php|publisher=The PHP Group|access-date=2009-09-11}}</ref>
|-
| {{Version |o | 4.4}}
| 11 July 2005<ref>{{cite web |title=PHP 4.4.0 Release Announcement |url=https://www.php.net/releases/4_4_0.php |access-date=25 October 2020}}</ref>
| 7 August 2008<ref name="eol" />
| Fixed a memory corruption bug, which required breaking binary compatibility with extensions compiled against PHP version 4.3.x.<ref name="php44announcement">{{cite web|title=PHP 4.4.0 Release Announcement|work=PHP Mannual|url=https://php.net/releases/4_4_0.php|publisher=The PHP Group|access-date=2013-11-24}}</ref>
|-
| {{Version |o | 5.0}}
| 13 July 2004<ref>{{cite web |title=PHP 5.0.0 Released! |url=https://news-web.php.net/php.announce/50 |access-date=25 October 2020}}</ref>
| 5 September 2005<ref name="eol" />
| Zend Engine II with a new object model.<ref name="php5changelog">{{cite web|title=PHP: PHP 5 ChangeLog|url=https://www.php.net/ChangeLog-5.php|publisher=The PHP Group|access-date=2008-02-22|date=2007-11-08}}</ref>
|-
| {{Version |o | 5.1}}
| 24 November 2005<ref>{{cite web |title=PHP 5.1.0 Release Announcement |url=https://www.php.net/releases/5_1_0.php |access-date=25 October 2020}}</ref>
| 24 August 2006<ref name="eol" />
| Performance improvements with the introduction of compiler variables in re-engineered PHP Engine.<ref name="php5changelog" /> Added PHP Data Objects (PDO) as a consistent interface for accessing databases.<ref name="phpPdoDocs">{{cite web|title=PHP manual: PDO|url=https://php.net/manual/en/intro.pdo.php|publisher=The PHP Group|access-date=2011-11-15|date=2011-11-15}}</ref>
|-
| {{Version |o | 5.2}}
| 2 November 2006<ref>{{cite web |title=PHP 5.2.0 Release Announcement |url=https://www.php.net/releases/5_2_0.php |access-date=25 October 2020}}</ref>
| 6 January 2011<ref name="eol" />
| Enabled the filter extension by default. Native [[JSON]] support.<ref name="php5changelog" />
|-
| {{Version |o | 5.3}}
| 30 June 2009<ref>{{cite web |title=PHP 5.3.0 Release Announcement |url=https://www.php.net/releases/5_3_0.php |access-date=25 October 2020}}</ref>
| 14 August 2014<ref name="eol" />
| [[Namespace]] support; [[name binding|late static bindings]], jump label (limited [[goto]]), [[anonymous function]]s, [[closure (computer programming)|closures]], PHP archives (phar), [[garbage collection (computer science)|garbage collection]] for circular references, improved [[Microsoft Windows|Windows]] support, sqlite3, mysqlnd as a replacement for libmysql as the underlying library for the extensions that work with [[MySQL]], fileinfo as a replacement for mime_magic for better [[MIME]] support, the Internationalization extension, and deprecation of ereg extension.
|-
| {{Version |o | 5.4}}
| 1 March 2012<ref>{{cite web |title=PHP 5.4.0 Release Announcement |url=https://www.php.net/releases/5_4_0.php |access-date=25 October 2020}}</ref>
| 3 September 2015<ref name="eol" />
| [[trait (computer programming)|Trait]] support, short array syntax support. Removed items: <code>register_globals</code>, <code>safe_mode</code>, <code>allow_call_time_pass_reference</code>, {{code|lang=php|code=session_register()}}, {{code|lang=php|code=session_unregister()}} and {{code|lang=php|code=session_is_registered()}}. Built-in web server.<ref>{{cite web|url=https://php.net/manual/en/features.commandline.webserver.php |title=Built-in web server |access-date=March 26, 2012}}</ref> Several improvements to existing features, performance and reduced memory requirements.
|-
| {{Version |o | 5.5}}
| 20 June 2013<ref>{{cite web |title=PHP 5.5.0 Release Announcement |url=https://www.php.net/releases/5_5_0.php |access-date=25 October 2020}}</ref>
| 10 July 2016<ref name="supportedversions">{{cite web|url=https://php.net/supported-versions.php |title=Supported Versions |website=php.net |access-date=2017-12-13}}</ref>
| Support for [[generator (computer programming)|generators]], <code>finally</code> blocks for exceptions handling, OpCache (based on Zend Optimizer+) bundled in official distribution.<ref name="55changes">{{cite web|title=PHP 5.5.0 changes|url=https://php.net/manual/en/migration55.new-features.php|access-date=2015-03-03|website=php.net}}</ref>
|-
| {{Version |o | 5.6}}
| 28 August 2014<ref>{{cite web |title=PHP 5.6.0 Release Announcement |url=https://www.php.net/releases/5_6_0.php |access-date=25 October 2020}}</ref>
| 31 December 2018<ref name="supportedversions"/>
| Constant scalar expressions, [[variadic function]]s, argument unpacking, new exponentiation operator, extensions of the <code>use</code> statement for functions and constants, new <code>phpdbg</code> debugger as a SAPI module, and other smaller improvements.<ref name="56changes">{{cite web |title=Migrating from PHP 5.5.x to PHP 5.6.x |url=https://www.php.net/manual/en/migration56.new-features.php |access-date=2014-03-24 |website=php.net}}</ref>
|-
| style="background:silver;"| 6.x
| {{n/a|Not released}}
| {{n/a}}
| Abandoned version of PHP that planned to include native Unicode support.<ref>{{cite web|url=https://lwn.net/Articles/379909/|title=Resetting PHP 6|quote=There have been books on the shelves purporting to cover PHP 6 since at least 2008. But, in March 2010, the PHP 6 release is not out{{snd}} in fact, it is not even close to out. Recent events suggest that PHP 6 will not be released before 2011{{snd}} if, indeed, it is released at all.}}</ref><ref>{{cite web|url=http://www.infoworld.com/article/2841561/php/php-7-moves-full-speed-ahead.html|title=PHP 7 moves full speed ahead|quote=Recent versions of PHP have been part of the 5.x release series, but there will be no PHP 6. "We're going to skip [version] 6, because years ago, we had plans for a 6, but those plans were very different from what we're doing now," Gutmans said. Going right to version 7 avoids confusion.|date=2014-10-31}}</ref>
|-
| {{Version |o | 7.0}}
| 3 December 2015<ref name=php7final>{{cite web |url=https://php.net/archive/2018.php#id2018-07-19-2|title=News Archive – 2018: PHP 7.2.9 Released |date=2018-08-16 |access-date=2018-08-16 |website=php.net}}</ref>
| 10 January 2019<ref name="releaseprocess" />
| Zend Engine 3 (performance improvements<ref name="phpng" /> and 64-bit integer support on Windows<ref>{{cite web|url=https://wiki.php.net/rfc/size_t_and_int64_next|title=PHP: rfc:size_t_and_int64_next|website=php.net|access-date=16 December 2014}}</ref>), uniform variable syntax,<ref name="uvs" /> [[Abstract Syntax Tree|AST]]-based compilation process,<ref>{{cite web|url=https://wiki.php.net/rfc/abstract_syntax_tree|title=PHP: rfc:abstract_syntax_tree|website=php.net|access-date=16 December 2014}}</ref> added {{code|lang=php|code=Closure::call()}},<ref>{{cite web|url=https://wiki.php.net/rfc/closure_apply|title=PHP: rfc:closure_apply|website=php.net|access-date=16 December 2014}}</ref> bitwise shift consistency across platforms,<ref>{{cite web|url=https://wiki.php.net/rfc/integer_semantics|title=PHP: rfc:integer_semantics|website=php.net|access-date=16 December 2014}}</ref> {{code|lang=php|code=??}} ([[Null coalescing operator|null coalesce]]) operator,<ref>{{cite web|url=https://wiki.php.net/rfc/isset_ternary|title=PHP: rfc:isset_ternary|website=php.net|access-date=16 December 2014}}</ref> [[Unicode]] code point [[String literal#Escape sequences|escape syntax]],<ref>{{cite web|url=https://wiki.php.net/rfc/unicode_escape|title=RFC: Unicode Codepoint Escape Syntax|date=2014-11-24|access-date=2014-12-19}}</ref> return type declarations,<ref name="return-types" /> scalar type (integer, float, string and boolean) declarations,<ref name="scalar-types" /> <code><=></code> "spaceship" [[three-way comparison]] operator,<ref>{{cite web|url=https://wiki.php.net/rfc/combined-comparison-operator|title=Combined Comparison (Spaceship) Operator|website=php.net|access-date=2015-05-21}}</ref> [[Generator (computer programming)|generator]] delegation,<ref>{{cite web|url=https://wiki.php.net/rfc/generator-delegation|title=PHP RFC: Generator Delegation|access-date=2015-05-21|website=php.net}}</ref> [[anonymous class]]es,<ref>{{cite web|url=https://wiki.php.net/rfc/anonymous_classes|title=PHP RFC: Anonymous Classes|access-date=2015-05-21|website=php.net}}</ref> simpler and more consistently available [[CSPRNG]] API,<ref>{{cite web|url=https://wiki.php.net/rfc/easy_userland_csprng|title=PHP RFC: Easy User-land CSPRNG|access-date=2015-05-21|website=php.net}}</ref> replacement of many remaining internal PHP "errors" with the more modern [[Exception (computer science)|exceptions]],<ref name="engine_exceptions">{{cite web|url=https://wiki.php.net/rfc/engine_exceptions_for_php7|title=PHP RFC: Exceptions in the engine (for PHP 7)|access-date=2015-05-21|website=php.net}}</ref> and shorthand syntax for importing multiple items from a namespace.<ref>{{cite web|url=https://wiki.php.net/rfc/group_use_declarations|title=PHP RFC: Group Use Declarations|access-date=2015-05-21|website=php.net}}</ref>
|-
| {{Version |o | 7.1}}
| 1 December 2016
| 1 December 2019<ref name="supportedversions"/>
| {{code|lang=php|iterable}} type,<ref>{{cite web|url=https://wiki.php.net/rfc/iterable|title=PHP: rfc:iterable|website=php.net|date=2016-06-10|access-date=2023-06-30}}</ref> nullable types,<ref>{{cite web|url=https://wiki.php.net/rfc/nullable_types|title=PHP: rfc:nullable_types|website=php.net|date=2014-04-10|access-date=2023-06-30}}</ref> [[Void type|{{code|lang=php|void}} return type]],<ref>{{cite web|url=http://wiki.php.net/rfc/void_return_type|title=PHP: rfc:void_return_type|website=php.net|date=2015-11-09|access-date=2015-11-14}}</ref> class constant [[information hiding|visibility modifiers]],<ref>{{cite web|url=https://wiki.php.net/rfc/class_const_visibility|title=PHP: rfc:class_constant_visibility|website=php.net|date=2015-10-27|access-date=2015-12-08}}</ref> short list syntax,<ref>{{cite web|url=https://wiki.php.net/rfc/short_list_syntax|title=PHP: rfc:short_list_syntax|website=php.net|date=2016-04-07|access-date=2023-06-30}}</ref> multi-catch<ref>{{cite web|url=https://wiki.php.net/rfc/multiple-catch|title=PHP: rfc:multiple-catch|website=php.net|date=2016-03-06|access-date=2023-06-30}}</ref>
|-
| {{Version |o | 7.2}}
| 30 November 2017
| 30 November 2020<ref name="supportedversions"/>
| Object parameter and return type declaration,<ref>{{cite web|url=https://wiki.php.net/rfc/object-typehint|title=PHP: rfc:object-typehint|website=wiki.php.net}}</ref> libsodium extension,<ref>{{cite web|url=https://wiki.php.net/rfc/libsodium|title=PHP: rfc:libsodium|website=wiki.php.net}}</ref> abstract method overriding,<ref>{{cite web|url=https://wiki.php.net/rfc/allow-abstract-function-override|title=PHP: rfc:allow-abstract-function-override|website=wiki.php.net}}</ref> parameter type widening<ref>{{cite web|url=https://wiki.php.net/rfc/parameter-no-type-variance|title=PHP: rfc:parameter-no-type-variance|website=wiki.php.net}}</ref>
|-
| {{Version |o | 7.3}}
| 6 December 2018<ref>{{cite web|url=https://wiki.php.net/todo/php73|title=PHP: todo:php73|website=wiki.php.net}}</ref>
| 6 December 2021
| Flexible [[Here document#PHP|Heredoc]] and Nowdoc syntax,<ref>{{cite web|url=https://wiki.php.net/rfc/flexible_heredoc_nowdoc_syntaxes|title=PHP: rfc:flexible_heredoc_nowdoc_syntaxes|website=wiki.php.net}}</ref> support for reference assignment and array deconstruction with {{code|lang=php|code=list()}},<ref>{{cite web|url=https://wiki.php.net/rfc/list_reference_assignment|title=PHP: rfc:list_reference_assignment|website=wiki.php.net}}</ref> PCRE2 support,<ref>{{cite web|url=https://wiki.php.net/rfc/pcre2-migration|title=PHP: rfc:pcre2-migration|website=wiki.php.net}}</ref> {{code|lang=php|code=hrtime}} function<ref>{{cite web|url=https://php.net/manual/en/function.hrtime.php|title=PHP: hrtime{{snd}} Manual|website=php.net}}</ref>
|-
| {{Version |o | 7.4}}
| 28 November 2019<ref>{{Cite web|url=https://www.php.net/archive/2019.php#2019-11-28-1|title=PHP 7.4.0 Released!|website=php.net|access-date=2019-11-28}}</ref>
| 28 November 2022
| Typed properties 2.0,<ref>{{Cite web|url=https://wiki.php.net/rfc/typed_properties_v2|title=PHP: rfc:typed_properties_v2|website=wiki.php.net|access-date=2019-04-04}}</ref> preloading,<ref>{{Cite web|url=https://wiki.php.net/rfc/preload|title=PHP: rfc:preload|website=wiki.php.net|access-date=2019-04-04}}</ref> null-coalescing assignment operator,<ref>{{Cite web|url=https://wiki.php.net/rfc/null_coalesce_equal_operator|title=PHP: rfc:null_coalesce_equal_operator|website=wiki.php.net|access-date=2019-04-04}}</ref> improve {{code|lang=php|code=openssl_random_pseudo_bytes}},<ref>{{Cite web|url=https://wiki.php.net/rfc/improve-openssl-random-pseudo-bytes|title=PHP: rfc:improve-openssl-random-pseudo-bytes|website=wiki.php.net|access-date=2019-04-04}}</ref> weak references,<ref name="php-8-weak-refs">{{Cite web|url=https://wiki.php.net/rfc/weakrefs|title=PHP: rfc:weakrefs|website=wiki.php.net|access-date=2019-04-05}}</ref> [[Foreign function interface|foreign function interface (FFI)]],<ref>{{Cite web|url=https://wiki.php.net/rfc/ffi|title=PHP: rfc:ffi|website=wiki.php.net|access-date=2019-04-05}}</ref> always available hash extension,<ref>{{Cite web|url=https://wiki.php.net/rfc/permanent_hash_ext|title=PHP: rfc:permanent_hash_ext|website=wiki.php.net|access-date=2019-04-05}}</ref> password hash registry,<ref>{{Cite web|url=https://wiki.php.net/rfc/password_registry|title=PHP: rfc:password_registry|website=wiki.php.net|access-date=2019-04-05}}</ref> multibyte string splitting,<ref>{{Cite web|url=https://wiki.php.net/rfc/mb_str_split|title=PHP: rfc:mb_str_split|website=wiki.php.net|access-date=2019-04-05}}</ref> reflection for references,<ref>{{Cite web|url=https://wiki.php.net/rfc/reference_reflection|title=PHP: rfc:reference_reflection|website=wiki.php.net|access-date=2019-04-05}}</ref> unbundle ext/wddx,<ref>{{Cite web|url=https://wiki.php.net/rfc/deprecate-and-remove-ext-wddx|title=PHP: rfc:deprecate-and-remove-ext-wddx|website=wiki.php.net|access-date=2019-04-05}}</ref> new custom object serialization mechanism<ref>{{Cite web|url=https://wiki.php.net/rfc/custom_object_serialization|title=PHP: rfc:custom_object_serialization|website=wiki.php.net|access-date=2019-04-05}}</ref>
|-
| {{Version |o | 8.0}}
| 26 November 2020<ref>{{Cite web|url=https://www.php.net/supported-versions.php|title=PHP: Supported Versions|website=php.net|access-date=2023-11-26}}</ref>
| 26 November 2023
| [[just-in-time compilation|Just-In-Time (JIT) compilation]],<ref name="php-8-JIT">{{Cite web|url=https://wiki.php.net/rfc/jit|title=PHP: rfc:jit|website=wiki.php.net|access-date=2019-04-05}}</ref> arrays starting with a negative index,<ref>{{Cite web|url=https://wiki.php.net/rfc/negative_array_index|title=PHP: rfc:negative_array_index|website=wiki.php.net|access-date=2019-04-05}}</ref> stricter/saner language semantics (validation for abstract trait methods),<ref>{{cite web |title=PHP RFC: Validation for abstract trait methods |url=https://wiki.php.net/rfc/abstract_trait_method_validation |website=wiki.php.net |access-date=14 August 2020}}</ref> saner string to number comparisons,<ref>{{cite web |title=PHP RFC: Saner string to number comparisons |url=https://wiki.php.net/rfc/string_to_number_comparison |website=wiki.php.net |access-date=14 August 2020}}</ref> saner numeric strings,<ref>{{cite web |title=PHP RFC: Saner numeric strings |url=https://wiki.php.net/rfc/saner-numeric-strings |website=wiki.php.net |access-date=14 August 2020}}</ref> {{code|lang=php|TypeError}} on invalid arithmetic/bitwise operators,<ref>{{cite web |title=PHP RFC: Stricter type checks for arithmetic/bitwise operators |url=https://wiki.php.net/rfc/arithmetic_operator_type_checks |website=wiki.php.net |access-date=14 August 2020}}</ref> reclassification of various engine errors,<ref>{{cite web |title=PHP RFC: Reclassifying engine warnings |url=https://wiki.php.net/rfc/engine_warnings |website=wiki.php.net |access-date=14 August 2020}}</ref> consistent type errors for internal functions,<ref>{{Cite web|url=https://wiki.php.net/rfc/consistent_type_errors|title=PHP: rfc:consistent_type_errors|website=wiki.php.net|access-date=2019-04-05}}</ref> fatal error for incompatible method signatures<ref>{{Cite web|url=https://wiki.php.net/rfc/lsp_errors|title=PHP: rfc:lsp_errors|website=wiki.php.net|access-date=2019-05-26}}</ref>), locale-independent float to string conversion,<ref>{{cite web |title=PHP RFC: Locale-independent float to string cast |url=https://wiki.php.net/rfc/locale_independent_float_to_string |website=wiki.php.net |access-date=14 August 2020}}</ref> variable syntax tweaks,<ref>{{cite web |title=PHP RFC: Variable Syntax Tweaks |url=https://wiki.php.net/rfc/variable_syntax_tweaks|website=wiki.php.net |access-date=14 August 2020}}</ref> attributes,<ref>{{cite web |title=PHP RFC: Attributes V2 |url=https://wiki.php.net/rfc/attributes_v2 |website=wiki.php.net |access-date=14 August 2020}}</ref><ref>{{Cite web|title=PHP RFC: Attribute Amendments|url=https://wiki.php.net/rfc/attribute_amendments |website=wiki.php.net |access-date=14 August 2020}}</ref><ref>{{Cite web|title=PHP RFC: Shorter Attribute Syntax|url=https://wiki.php.net/rfc/shorter_attribute_syntax|access-date=2020-06-20|website=wiki.php.net}}</ref><ref>{{cite web |title=PHP RFC: Shorter Attribute Syntax Change |url=https://wiki.php.net/rfc/shorter_attribute_syntax_change |website=wiki.php.net |access-date=14 August 2020}}</ref> named arguments,<ref>{{cite web |title=PHP RFC: Named Arguments |url=https://wiki.php.net/rfc/named_params |website=wiki.php.net |access-date=14 August 2020}}</ref> match expression,<ref>{{cite web |title=PHP RFC: Match expression v2 |url=https://wiki.php.net/rfc/match_expression_v2 |website=wiki.php.net |access-date=14 August 2020}}</ref> constructor property promotion,<ref>{{cite web |title=PHP RFC: Constructor Property Promotion |url=https://wiki.php.net/rfc/constructor_promotion |website=wiki.php.net |access-date=14 August 2020}}</ref> union types,<ref>{{cite web |title=PHP RFC: Union Types 2.0 |url=https://wiki.php.net/rfc/union_types_v2 |website=wiki.php.net |access-date=14 August 2020}}</ref> {{code|lang=php|mixed}} type,<ref>{{cite web |title=PHP RFC: Mixed Type v2 |url=https://wiki.php.net/rfc/mixed_type_v2 |website=wiki.php.net |access-date=14 August 2020}}</ref> static return type,<ref>{{cite web |title=PHP RFC: Static return type |url=https://wiki.php.net/rfc/static_return_type |website=wiki.php.net |access-date=14 August 2020}}</ref> nullsafe operator,<ref name="nullsafe-operator-rfc">{{cite web |title=PHP RFC: Nullsafe operator |url=https://wiki.php.net/rfc/nullsafe_operator |website=wiki.php.net |access-date=14 August 2020}}</ref> non-capturing catches,<ref>{{cite web |title=PHP RFC: non-capturing catches |url=https://wiki.php.net/rfc/non-capturing_catches |website=wiki.php.net |access-date=14 August 2020}}</ref> {{code|lang=php|throw}} expression,<ref name="throw-expression-php8">{{cite web |title=PHP RFC: throw expression |url=https://wiki.php.net/rfc/throw_expression |website=wiki.php.net |access-date=14 August 2020}}</ref> JSON extension is always available.<ref name="ext-json-always-available">{{cite web |last1=Andre |first1=Tyson |title=PHP RFC: Always available JSON extension |url=https://wiki.php.net/rfc/always_enable_json |website=PHP |access-date=25 October 2020}}</ref>
|-
| {{Version |co | 8.1}}
| 25 November 2021<ref>{{Cite web |title=PHP: todo:php81 |url=https://wiki.php.net/todo/php81 |access-date=2022-06-16 |website=wiki.php.net}}</ref>
| 25 November 2024
| Explicit octal integer literal notation,<ref>{{Cite web|url=https://wiki.php.net/rfc/explicit_octal_notation|title=PHP RFC: Explicit octal integer literal notation|website=wiki.php.net|access-date=2020-11-25}}</ref> enumerations,<ref>{{Cite web|url=https://wiki.php.net/rfc/enumerations|title=PHP RFC: Enumerations|website=wiki.php.net|access-date=2021-03-25}}</ref> read-only properties,<ref>{{Cite web|title=PHP: rfc:readonly_properties_v2|url=https://wiki.php.net/rfc/readonly_properties_v2|access-date=2021-11-26|website=wiki.php.net}}</ref> first-class callable syntax,<ref>{{Cite web|title=PHP: rfc:first_class_callable_syntax|url=https://wiki.php.net/rfc/first_class_callable_syntax|access-date=2021-11-26|website=wiki.php.net}}</ref> {{code|lang=php|new}} in initializers,<ref>{{Cite web|title=PHP: rfc:new_in_initializers|url=https://wiki.php.net/rfc/new_in_initializers|access-date=2021-11-26|website=wiki.php.net}}</ref> pure intersection types,<ref>{{Cite web|title=PHP: rfc:pure-intersection-types|url=https://wiki.php.net/rfc/pure-intersection-types|access-date=2021-11-26|website=wiki.php.net}}</ref> {{code|lang=php|never}} return type,<ref>{{Cite web|title=PHP: rfc:noreturn_type|url=https://wiki.php.net/rfc/noreturn_type|access-date=2021-11-26|website=wiki.php.net}}</ref> {{code|lang=php|final}} class constraints,<ref>{{Cite web|title=PHP: rfc:final_class_const|url=https://wiki.php.net/rfc/final_class_const|access-date=2021-11-26|website=wiki.php.net}}</ref> fibers<ref>{{Cite web|title=PHP: rfc:fibers|url=https://wiki.php.net/rfc/fibers|access-date=2021-11-26|website=wiki.php.net}}</ref>
|-
| {{Version |co |8.2}}
| 8 December 2022<ref>{{Cite web |title=PHP: todo:php82 |url=https://wiki.php.net/todo/php82 |access-date=2022-06-16 |website=wiki.php.net}}</ref>
| 8 December 2025
| Readonly classes,<ref>{{Cite web |title=PHP: rfc:readonly_classes |url=https://wiki.php.net/rfc/readonly_classes |access-date=2022-06-16 |website=wiki.php.net}}</ref> {{code|lang=php|code=null}}, {{code|lang=php|code=false}}, and {{code|lang=php|code=true}} as stand-alone types,<ref>{{Cite web |title=PHP: rfc:null-false-standalone-types |url=https://wiki.php.net/rfc/null-false-standalone-types |access-date=2022-06-16 |website=wiki.php.net}}</ref><ref>{{Cite web |title=PHP: rfc:true-type |url=https://wiki.php.net/rfc/true-type |access-date=2022-06-16 |website=wiki.php.net}}</ref> locale-independent case conversion,<ref>{{Cite web |title=PHP: rfc:strtolower-ascii |url=https://wiki.php.net/rfc/strtolower-ascii |access-date=2022-06-16 |website=wiki.php.net}}</ref> disjunctive normal form types,<ref>{{Cite web |title=PHP: rfc:dnf_types |url=https://wiki.php.net/rfc/dnf_types |access-date=2023-02-07 |website=wiki.php.net}}</ref> constants in traits<ref>{{Cite web |title=PHP: rfc:constants_in_traits |url=https://wiki.php.net/rfc/constants_in_traits |access-date=2023-02-07 |website=wiki.php.net}}</ref>
|-
| {{Version |c | 8.3}}
| 23 November 2023<ref>{{Cite web |date=23 November 2023 |title=PHP 8.3.0 Released! |url=https://www.php.net/archive/2023.php#2023-11-23-2 |access-date=24 November 2023 |website=php.net}}</ref>
| 23 November 2026
| Typed class constants,<ref>{{Cite web |title=PHP: rfc:typed_class_constants |url=https://wiki.php.net/rfc/typed_class_constants |access-date=2023-12-17 |website=wiki.php.net}}</ref> dynamic class constant fetch,<ref>{{Cite web |title=PHP: rfc:dynamic_class_constant_fetch |url=https://wiki.php.net/rfc/dynamic_class_constant_fetch |access-date=2023-12-17 |website=wiki.php.net}}</ref> {{code|lang=php|code=#[\Override]}} attribute,<ref>{{Cite web |title=PHP: rfc:marking_overriden_methods |url=https://wiki.php.net/rfc/marking_overriden_methods |access-date=2023-12-17 |website=wiki.php.net}}</ref> deep-cloning of read-only properties,<ref>{{Cite web |title=PHP: rfc:readonly_amendments |url=https://wiki.php.net/rfc/readonly_amendments |access-date=2023-12-17 |website=wiki.php.net}}</ref> new {{code|lang=php|code=json_validate}} function,<ref>{{Cite web |title=PHP: rfc:json_validate |url=https://wiki.php.net/rfc/json_validate |access-date=2023-12-17 |website=wiki.php.net}}</ref> randomizer additions,<ref>{{Cite web |title=PHP: rfc:randomizer_additions |url=https://wiki.php.net/rfc/randomizer_additions |access-date=2023-12-17 |website=wiki.php.net}}</ref> the command-line linter supports multiple files
|-
| {{Version |p | 8.4}}
| 21 November 2024<ref>{{Cite web |date=26 March 2024 |title=PHP: todo: php84|url=https://wiki.php.net/todo/php84 |access-date=26 March 2024 |website=php.net}}</ref>
| 21 November 2027
|
|- class="sortbottom"
| colspan="4" | {{Version |l |show=111101}}
|}
Beginning on 28 June 2011, the PHP Development Team implemented a timeline for the release of new versions of PHP.<ref name="releaseprocess">{{cite web|title=PHP: Release Process|url=https://wiki.php.net/rfc/releaseprocess|access-date=2013-10-06|date=2011-06-20}}</ref> Under this system, at least one release should occur every month. Once per year, a minor release should occur which may include new features. Every minor release should at least be supported for two years with security and bug fixes, followed by at least one year of only security fixes, for a total of a three-year release process for every minor release. No new features, unless small and self-contained, are to be introduced into a minor release during the three-year release process.
== <span id=ELEPHPANT>Mascot</span> ==
[[File:Webysther 20160423 - Elephpant.svg|thumb|200px|The elePHPant, PHP mascot]]
The mascot of the PHP project is the ''elePHPant'', a blue [[elephant]] with the PHP logo on its side, designed by Vincent Pontier<ref>{{cite web|title=PHP: ElePHPant|url=https://php.net/elephpant.php|date=4 Oct 2014|access-date=4 Oct 2014}}</ref> in 1998.<ref>{{cite web|url=https://wwphp-fb.github.io/faq/community/elephpant/|title=Redirecting…|website=wwphp-fb.github.io}}</ref> "The (PHP) letters were forming the shape of an elephant if viewed in a sideways angle."<ref>{{cite web|url=https://7php.com/elephpant/|title=The PHP Mascot's Birth - Creator Of The elePHPant Vincent Pontier Reveals The True Story!|website=7php.com|date=2014-01-06}}</ref> The elePHPant is sometimes differently coloured when in [[plush toy]] form.<ref>{{Cite web |title=ElePHPant |url=https://docs.php.earth/php/community/elephpant/ |access-date=2024-02-13 |website=PHP.earth |language=en}}</ref>
Many variations of this mascot have been made over the years. Only the elePHPants based on the original design by Vincent Pontier are considered official by the community.<ref>{{Cite web|url=https://www.php.net/elephpant.php|title=PHP: ElePHPant|website=www.php.net}}</ref> These are collectable and some of them are extremely rare.<ref>{{Cite web|url=https://afieldguidetoelephpants.net/|title=A Field Guide to Elephpants|website=afieldguidetoelephpants.net}}</ref>
== Syntax ==
{{Main|PHP syntax and semantics}}
[[File:"Hello World" Application in PHP.png|thumb|A "Hello World" application in PHP 7.4 running on its built-in development server]]
The following [["Hello, World!" program]] is written in PHP code embedded in an [[HTML]] document:
<syntaxhighlight lang="html+php" highlight="7-9">
<!DOCTYPE html>
<html>
<head>
<title>PHP "Hello, World!" program</title>
</head>
<body>
<p><?= 'Hello, World!' ?></p>
</body>
</html>
</syntaxhighlight>
However, as no requirement exists for PHP code to be embedded in HTML, the simplest version of ''Hello, World!'' may be written like this, with the closing tag <syntaxhighlight lang="PHP" inline="">?></syntaxhighlight> omitted as preferred in files containing pure PHP code.<ref>{{cite web|url=https://www.php.net/manual/en/language.basic-syntax.phptags.php |title=tags{{snd}} Manual |website=php.net |access-date=2014-02-17}}</ref>
<syntaxhighlight lang="php5">
<?php echo 'Hello, World!';
</syntaxhighlight>
The PHP interpreter only executes PHP code within its [[delimiter]]s. Anything outside of its delimiters is not processed by PHP, although the non-PHP text is still subject to [[control structure]]s described in PHP code. The most common delimiters are <syntaxhighlight lang="PHP" inline=""><?php</syntaxhighlight> to open and <syntaxhighlight lang="PHP" inline="">?></syntaxhighlight> to close PHP sections. The shortened form <syntaxhighlight lang="PHP" inline=""><?</syntaxhighlight> also exists. This short delimiter makes script files less portable since support for them can be disabled in the local PHP configuration and it is therefore discouraged.<ref name="rfc-shortags" /><ref name="basic syntax">{{cite web|title=PHP: Basic syntax|url=https://www.php.net/manual/en/language.basic-syntax.php|publisher=The PHP Group|access-date=2008-02-22}}</ref> Conversely, there is no recommendation against the echo short tag <syntaxhighlight lang="PHP" inline=""><?=</syntaxhighlight>.<ref>{{cite web|access-date=2016-01-03|url=https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md|title=Basic Coding Standard|publisher=PHP Framework Interoperability Group}}</ref> Prior to PHP 5.4.0, this short syntax for <syntaxhighlight lang="php" inline="">echo</syntaxhighlight> only works with the <code>short_open_tag</code> configuration setting enabled, while for PHP 5.4.0 and later it is always available.<ref>{{cite web|url=https://www.php.net/echo |title=echo{{snd}} Manual |website=php.net |access-date=2014-02-17}}</ref><ref>{{cite web|url=https://www.php.net/manual/en/ini.core.php#ini.short-open-tag |title=Description of core php.ini directives{{snd}} Manual |website=php.net |date=2002-03-17 |access-date=2014-02-17}}</ref><ref name="rfc-shortags">{{cite web |url=http://wiki.php.net/rfc/shortags |title=PHP: rfc:shortags |website=php.net |date=2008-04-03 |access-date=2014-05-08 }}</ref> The purpose of all these delimiters is to separate PHP code from non-PHP content, such as [[JavaScript]] code or HTML markup.<ref>{{cite web|access-date=2008-02-25|url=https://www.php.net/manual/en/tutorial.firstpage.php|title=Your first PHP-enabled page |publisher=The PHP Group}}</ref> So the shortest [["Hello, World!" program]] written in PHP is:
<syntaxhighlight lang="html+php">
<?='Hello, World!';
</syntaxhighlight>
The first form of delimiters, <syntaxhighlight lang="PHP" inline><?php</syntaxhighlight> and <syntaxhighlight lang="PHP" inline>?></syntaxhighlight>, in [[XHTML]] and other [[XML]] documents, creates correctly formed XML processing instructions.<ref>{{cite web | url = http://www.w3.org/TR/2008/REC-xml-20081126/#sec-pi | title = Processing Instructions | work = Extensible Markup Language (XML) 1.0 (Fifth Edition) | publisher = W3C | date = 26 November 2008 | last = Bray | first = Tim | access-date = 2009-06-18|display-authors=etal}}</ref> This means that the resulting mixture of PHP code and other markups in the server-side file is itself well-formed XML.
{{Anchor|TYPE-HINTING}}
Variables are [[Sigil (computer programming)|prefixed]] with a [[dollar sign|dollar symbol]], and a [[primitive type|type]] does not need to be specified in advance. PHP 5 introduced ''type declarations'' that allow functions to force their parameters to be objects of a specific class, arrays, interfaces or [[callback function]]s. However, before PHP 7, type declarations could not be used with scalar types such as integers or strings.<ref name="scalar-types" />
Below is an example of how PHP variables are declared and initialized.
<syntaxhighlight lang="php">
<?php
$name = 'John'; // variable of string type being declared and initialized
$age = 18; // variable of integer type being declared and initialized
$height = 5.3; // variable of double type being declared and initialized
echo $name . ' is ' . $height . "m tall\n"; // concatenating variables and strings
echo "$name is $age years old."; // interpolating variables to string
?>
</syntaxhighlight>
Unlike function and class names, variable names are case-sensitive. Both double-quoted ("") and [[heredoc]] strings provide the ability to interpolate a variable's value into the string.<ref>{{cite web|access-date=2008-03-16|url=https://www.php.net/manual/en/language.variables.php|title=Variables |publisher=The PHP Group}}</ref> PHP treats [[newline]]s as [[whitespace character|whitespace]] in the manner of a [[free-form language]], and statements are terminated by a semicolon.<ref>{{cite web|access-date=2008-03-16|url=https://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]]: <syntaxhighlight lang="PHP" inline>/* */</syntaxhighlight> marks block and inline comments; <syntaxhighlight lang="PHP" inline>//</syntaxhighlight> or <syntaxhighlight lang="PHP" inline>#</syntaxhighlight> are used for one-line comments.<ref>{{cite web|access-date=2008-03-16|url=https://www.php.net/manual/en/language.basic-syntax.comments.php|title=Comments |publisher=The PHP Group}}</ref> The <code>echo</code> statement is one of several facilities PHP provides to output text.{{Citation needed|date=November 2023}}
In terms of keywords and language syntax, PHP is similar to C-style syntax. <syntaxhighlight lang="PHP" inline>if</syntaxhighlight> conditions, <syntaxhighlight lang="PHP" inline>for</syntaxhighlight> and <syntaxhighlight lang="PHP" inline>while</syntaxhighlight> loops and function returns are similar in syntax to languages such as C, C++, C#, Java and Perl.{{Citation needed|date=November 2023}}
=== Data types ===
PHP is [[strong and weak typing|loosely typed]]. It stores integers in a platform-dependent range, either as a 32, 64 or 128-bit [[signed number representations|signed]] [[integer (computer science)|integer]] equivalent to the [[C variable types and declarations|C-language long type]]. Unsigned integers are converted to signed values in certain situations, which is different behaviour to many 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 = March 27, 2007 | publisher = MySQL Performance Blog | access-date = 2007-03-28}}</ref> Integer variables can be assigned using decimal (positive and negative), [[octal]], [[hexadecimal]], and [[binary code|binary]] notations.{{Citation needed|date=November 2023}}
[[Floating-point number]]s 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|access-date=2008-03-16|url=https://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; <code>NULL</code> is the only allowed value for this data type.<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, nowdoc or [[heredoc]] syntax.<ref>{{cite web|access-date=2008-03-21|url=https://www.php.net/manual/en/language.types.string.php|title=Strings |publisher=The PHP Group}}</ref>
The '''Standard PHP Library''' (SPL) attempts to solve standard problems and implements efficient data access interfaces and classes.<ref>{{cite web | url = https://www.php.net/spl | title = SPL – StandardPHPLibrary | date = March 16, 2009 | website = PHP.net | access-date = 2009-03-16}}</ref>
=== Functions ===
PHP defines a large array of functions in the core language and many are also available in various extensions; these functions are well documented online [https://www.php.net/docs.php PHP documentation].<ref name="functions" /> However, the built-in library has a wide variety of naming conventions and associated inconsistencies, as described under [[#History|history]] above.
Custom functions may be defined by the developer:
<syntaxhighlight lang="php">
function myAge(int $birthYear): string
{
// calculate the age by subtracting the birth year from the current year.
$yearsOld = date('Y') - $birthYear;
// return the age in a descriptive string.
return $yearsOld . ($yearsOld == 1 ? ' year' : ' years');
}
echo 'I am currently ' . myAge(1995) . ' old.';
</syntaxhighlight>
As of {{CURRENTYEAR}}, the output of the above sample program is "I am currently {{#expr: {{CURRENTYEAR}} - 1995}} years old."
In lieu of [[function pointer]]s, functions in PHP can be referenced by a string containing their name. In this manner, normal PHP functions can be used, for example, as [[Callback function|callbacks]] or within [[function table]]s.<ref name="variable-functions" /> User-defined functions may be created at any time without being [[Function prototype|prototyped]].<ref name="functions">{{cite web
| url = https://www.php.net/manual/en/functions.user-defined.php
| title = User-defined functions (PHP manual)
| date = 2014-07-04 | access-date = 2014-07-07
| website = php.net
}}</ref><ref name="variable-functions">{{cite web
| url = https://www.php.net/manual/en/functions.variable-functions.php
| title = Variable functions (PHP manual)
| date = 2014-07-04 | access-date = 2014-07-07
| website = php.net
}}</ref> Functions may be defined inside code blocks, permitting a [[dynamic dispatch|run-time decision]] as to whether or not a function should be defined. There is a <code>function_exists</code> function that determines whether a function with a given name has already been defined. Function calls must use parentheses, with the exception of zero-argument class [[constructor (computer science)|constructor]] functions called with the PHP operator <code>new</code>, in which case parentheses are optional.{{Citation needed|date=November 2023}}
Since PHP 4.0.1 <code>create_function()</code>, a thin wrapper around <code>eval()</code>, allowed normal PHP functions to be created during program execution; it was deprecated in PHP 7.2 and removed in PHP 8.0<ref>{{cite web
| url = https://www.php.net/manual/en/function.create-function.php
| title = create_function() (PHP manual)
| date = 2022-04-06 | access-date = 2022-05-04
| website = php.net
}}</ref> in favor of syntax for [[anonymous function]]s or "[[Closure (computer programming)|closure]]s"<ref>{{cite web
| url = https://www.php.net/manual/en/functions.anonymous.php
| title = Anonymous functions (PHP manual)
| date = 2014-07-04 | access-date = 2014-07-07
| website = php.net
}}</ref> that can capture variables from the surrounding scope, which was added in PHP 5.3. Shorthand arrow syntax was added in PHP 7.4:<ref>{{cite web
| url = https://www.php.net/manual/en/functions.arrow.php
| title = Arrow Functions (PHP manual)
| access-date = 2021-01-25
| website = php.net
}}</ref>
<syntaxhighlight lang="php">
function getAdder($x) {
return fn($y) => $x + $y;
}
$adder = getAdder(8);
echo $adder(2); // prints "10"
</syntaxhighlight>
In the example above, <code>getAdder()</code> function creates a closure using passed argument {{code|lang=php|code=$x}}, which takes an additional argument {{code|lang=php|code=$y}}, and returns the created closure to the caller. Such a function is a first-class object, meaning that it can be stored in a variable, passed as a [[parameter (computer programming)|parameter]] to other functions, etc.<ref>{{cite web
| url = http://wiki.php.net/rfc/closures
| title = Request for Comments: Lambda functions and closures
| date = 2008-07-01 | access-date = 2014-07-07
| author1 = Christian Seiler | author2 = Dmitry Stogov
| website = php.net
}}</ref>
Unusually for a dynamically typed language, PHP supports type declarations on function parameters, which are enforced at runtime. This has been supported for classes and interfaces since PHP 5.0, for arrays since PHP 5.1, for "callables" since PHP 5.4, and scalar (integer, float, string and boolean) types since PHP 7.0.<ref name="scalar-types" /> PHP 7.0 also has type declarations for function return types, expressed by placing the type name after the list of parameters, preceded by a colon.<ref name="return-types" /> For example, the <code>getAdder</code> function from the earlier example could be annotated with types like so in PHP 7:
<syntaxhighlight lang="php">
function getAdder(int $x): Closure
{
return fn(int $y): int => $x + $y;
}
$adder = getAdder(8);
echo $adder(2); // prints "10"
echo $adder(null); // throws an exception because an incorrect type was passed
$adder = getAdder([]); // would also throw an exception
</syntaxhighlight>
By default, scalar type declarations follow weak typing principles. So, for example, if a parameter's type is <code>int</code>, PHP would allow not only integers, but also convertible numeric strings, floats or booleans to be passed to that function, and would convert them.<ref name="scalar-types" /> However, PHP 7 has a "strict typing" mode which, when used, disallows such conversions for function calls and returns within a file.<ref name="scalar-types" />
=== PHP objects ===
Basic [[object-oriented programming]] functionality was added in PHP 3 and improved in PHP 4.<ref name="about PHP" /> This allowed for PHP to gain further abstraction, making creative tasks easier for programmers using the language. 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 [[value type]]s.<ref name="php 5 objects">{{cite web|access-date=2008-03-16|url=http://mjtsai.com/blog/2004/07/15/php-5-object-references/|title=PHP 5 Object References |website=mjtsai.com}}</ref> The drawback of this method was that code had to make heavy use of PHP's "reference" variables if it wanted to modify an object it was passed rather than creating a copy of it. In the new approach, objects are referenced by [[handle (computing)|handle]], and not by value.{{Citation needed|date=November 2023}}
PHP 5 introduced private and protected [[member variable]]s and methods, along with [[Abstract type|abstract classes]], [[Final type|final classes]], [[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 [[Interface (computing)|interfaces]] and allowed for multiple interfaces to be implemented. There are special interfaces that allow objects to interact with the runtime system. [[object (computer science)|Objects]] implementing ArrayAccess can be used with [[array data type|array]] syntax and objects 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|access-date=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 <code>clone</code>, the Zend engine will check whether a <code>__clone()</code> method has been defined. If not, it will call a default <code>__clone()</code> which will copy the object's properties. If a <code>__clone()</code> 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 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|access-date=2008-03-16|url=https://www.php.net/language.oop5.cloning|title=Object cloning |publisher=The PHP Group}}</ref>
The [[Visibility (computer science)|visibility]] of PHP properties and methods is defined using the [[Keyword (computer programming)|keywords]] <code>public</code>, <code>private</code>, and <code>protected</code>. The default is public, if only [[variable (programming)|var]] is used; <code>var</code> is a synonym for <code>public</code>. Items declared <code>public</code> can be accessed everywhere. <code>protected</code> limits access to [[inherited class]]es (and to the class that defines the item). <code>private</code> limits visibility only to the class that defines the item.<ref>{{cite web |url=http://theserverpages.com/php/manual/en/language.oop5.visibility.php |title=Visibility (PHP Manual) |website=theserverpages.com |date=2005-05-19 |access-date=2010-08-26 |archive-date=2010-09-24 |archive-url=https://web.archive.org/web/20100924033414/http://theserverpages.com/php/manual/en/language.oop5.visibility.php |url-status=dead }}</ref> Objects of the same type have access to each other's private and protected members even though they are not the same instance.{{Citation needed|date=November 2023}}
==== Example ====
The following is a basic example of [[object-oriented programming]] in PHP 8:
<syntaxhighlight lang="php" line>
<?php
abstract class User
{
protected string $name;
public function __construct(string $name)
{
// make first letter uppercase and the rest lowercase
$this->name = ucfirst(strtolower($name));
}
public function greet(): string
{
return "Hello, my name is " . $this->name;
}
abstract public function job(): string;
}
class Student extends User
{
public function __construct(string $name, private string $course)
{
parent::__construct($name);
}
public function job(): string
{
return "I learn " . $this->course;
}
}
class Teacher extends User
{
public function __construct(string $name, private array $teachingCourses)
{
parent::__construct($name);
}
public function job(): string
{
return "I teach " . implode(", ", $this->teachingCourses);
}
}
$students = [
new Student("Alice", "Computer Science"),
new Student("Bob", "Computer Science"),
new Student("Charlie", "Business Studies"),
];
$teachers = [
new Teacher("Dan", ["Computer Science", "Information Security"]),
new Teacher("Erin", ["Computer Science", "3D Graphics Programming"]),
new Teacher("Frankie", ["Online Marketing", "Business Studies", "E-commerce"]),
];
foreach ([$students, $teachers] as $users) {
echo $users[0]::class . "s:\n";
array_walk($users, function (User $user) {
echo "{$user->greet()}, {$user->job()}\n";
});
}
</syntaxhighlight>
This program outputs the following:
<pre>
Students:
Hello, my name is Alice, I learn Computer Science
Hello, my name is Bob, I learn Computer Science
Hello, my name is Charlie, I learn Business Studies
Teachers:
Hello, my name is Dan, I teach Computer Science, Information Security
Hello, my name is Erin, I teach Computer Science, 3D Graphics Programming
Hello, my name is Frankie, I teach Online Marketing, Business Studies, E-commerce
</pre>
<!-- Note that there are problems with the script in this section. -->
== Implementations ==
The only complete PHP implementation is the original, known simply as PHP. It is the most widely used and is powered by the [[Zend Engine]]. To disambiguate it from other implementations, it is sometimes unofficially called "Zend PHP". The Zend Engine [[Compiler|compiles]] PHP [[source code]] on-the-fly into an internal format that it can execute, thus it works as an [[Interpreter (computing)|interpreter]].<ref>{{cite web|access-date=2009-11-04|url=http://www.linux-tutorial.info/modules.php?name=Howto&pagename=Unix-and-Internet-Fundamentals-HOWTO/languages.html|title=How do computer languages work?|archive-date=2011-07-16|archive-url=https://web.archive.org/web/20110716214917/http://www.linux-tutorial.info/modules.php?name=Howto&pagename=Unix-and-Internet-Fundamentals-HOWTO/languages.html|url-status=dead}}</ref><ref>{{cite book |title=Beginning PHP and MySQL 5: From Novice to Professional |author=Gilmore, W. Jason |page=[https://archive.org/details/beginningphpmysq0000gilm/page/43 43] |date=2006-01-23 |publisher=Apress |isbn=1590595521 |url=https://archive.org/details/beginningphpmysq0000gilm/page/43 }}</ref> It is also the "reference implementation" of PHP, as PHP has no formal specification, and so the semantics of Zend PHP define the semantics of PHP. Due to the complex and nuanced semantics of PHP, defined by how Zend works, it is difficult for competing implementations to offer complete compatibility.{{Citation needed|date=November 2023}}
PHP's single-request-per-script-execution model, and the fact that the Zend Engine is an interpreter, leads to inefficiency; as a result, various products have been developed to help improve PHP performance. In order to speed up execution time and not have to compile the PHP source code every time the web page is accessed, PHP scripts can also be deployed in the PHP engine's internal format by using an [[opcode]] cache, which works by [[Cache (computing)|caching]] the compiled form of a PHP script (opcodes) in [[Shared memory (interprocess communication)|shared memory]] to avoid the overhead of [[parsing]] and [[compiling]] the code every time the script runs. An opcode cache, [[Zend Opcache]], is built into PHP since version 5.5.<ref>{{cite web
| title = [VOTE] Integrating Zend Optimizer+ into the PHP distribution
| url = http://news.php.net/php.internals/66531
| access-date = 2013-03-08
| website = news.php.net
}}</ref> Another example of a widely used opcode cache is the [[Alternative PHP Cache]] (APC), which is available as a [[PHP Extension Community Library|PECL]] extension.<ref>{{cite web
| url = http://www.php.net/manual/en/book.apc.php
| title = Alternative PHP Cache
| access-date = 2013-09-21
| website = PHP.net
| archive-date = 2013-11-15
| archive-url = https://web.archive.org/web/20131115071936/http://php.net/manual/en/book.apc.php
| url-status = dead
}}</ref>
While Zend PHP is still the most popular implementation, several other implementations have been developed. Some of these are [[compiler]]s or support [[JIT compilation]], and hence offer performance benefits over Zend PHP at the expense of lacking full PHP compatibility.{{Citation needed|date=November 2023}} Alternative implementations include the following:
* [[HHVM]] (HipHop Virtual Machine) – developed at Facebook and available as open source, it converts PHP code into a high-level bytecode (commonly known as an [[intermediate language]]), which is then translated into x86-64 machine code dynamically at runtime by a [[Just-in-time compiler|just-in-time]] (JIT) compiler, resulting in up to 6× performance improvements.<ref>{{cite web|url=http://www.hhvm.com/blog/2813/we-are-the-98-5-and-the-16 |title=We are the 98.5% (and the 16%) « HipHop Virtual Machine |website=hhvm.com |date=December 2013 |access-date=2014-02-23}}</ref> However, since version 7.2 Zend has outperformed HHVM,<ref>{{Cite web|url=https://kinsta.com/blog/php-benchmarks/|title=The Definitive PHP 5.6, 7.0, 7.1, 7.2 & 7.3 Benchmarks (2019)|date=2019-01-14 |access-date=2019-04-19}}</ref> and HHVM 3.24 is the last version to officially support PHP.<ref>{{Cite web|url=https://www.infoworld.com/article/3226489/web-development/forget-php-facebooks-hhvm-engine-switches-to-hack-instead.html|title=Forget PHP! Facebook's HHVM engine switches to Hack instead|last=Krill|first=Paul|date=2017-09-20|website=InfoWorld |access-date=2019-02-06}}</ref>
** [[HipHop for PHP|HipHop]] – developed at Facebook and available as open source, it transforms the PHP scripts into [[C++]] code and then compiles the resulting code, reducing the server load up to 50%. In early 2013, Facebook deprecated it in favour of HHVM due to multiple reasons, including deployment difficulties and lack of support for the whole PHP language, including the <code>create_function()</code> and <code>eval()</code> constructs.<ref>{{cite web|title=Announcement on GitHub removing HPHPc support|website=[[GitHub]]|url=https://github.com/facebook/hiphop-php/commit/fc5b95110ff75110ad55bb97f7c93a8c4eb68e3b|access-date=2013-05-24}}</ref>
* [[Parrot virtual machine|Parrot]] – a virtual machine designed to run dynamic languages efficiently; the cross-translator Pipp transforms the PHP source code into the [[Parrot intermediate representation]], which is then translated into the Parrot's bytecode and executed by the virtual machine.
* [[PeachPie]] – a second-generation compiler to .[[.NET Framework|NET]] [[Common Intermediate Language]] (CIL) bytecode, built on the [[Roslyn (compiler)|Roslyn]] platform; successor of Phalanger, sharing several architectural components
* [[Phalanger (compiler)|Phalanger]] – compiles PHP into .Net Common Intermediate Language bytecode; predecessor of PeachPie
* [[Quercus (software)|Quercus]] – compiles PHP into [[Java bytecode]]
== Licensing ==
{{Main|PHP License}}
PHP is [[free software]] released under the [[PHP License]], which stipulates that:<ref>{{cite web|url=https://www.php.net/license/3_01.txt |title=The PHP License, version 3.01|access-date=2010-05-20}}</ref>
{{blockquote
| Products derived from this software may not be called "PHP", nor may "PHP" appear in their name, without prior written permission from group@php.net. You may indicate that your software works in conjunction with PHP by saying "[[Foo]] for PHP" instead of calling it "PHP Foo" or "phpfoo".
}}
This restriction on the use of "PHP" makes the PHP License incompatible with the [[General Public License]] (GPL), while the Zend License is incompatible due to an advertising clause similar to that of the original [[BSD license]].<ref>{{cite web | title = GPL-Incompatible, Free Software Licenses | url = https://www.gnu.org/licenses/license-list.html#GPLIncompatibleLicenses | work = Various Licenses and Comments about Them | publisher = Free Software Foundation|access-date=2011-01-03}}</ref>
== <span id=PDO><span id=ZEPHIR>Development and community</span></span> ==
PHP includes various [[list of PHP libraries|free and open-source libraries]] in its source distribution or uses them in resulting PHP binary builds. PHP is fundamentally an [[Internet]]-aware system with built-in modules for accessing [[File Transfer Protocol]] (FTP) servers and many database servers, including [[PostgreSQL]], [[MySQL]], [[Microsoft SQL Server]] and [[SQLite]] (which is an embedded database), [[Lightweight Directory Access Protocol|LDAP]] servers, and others. Numerous functions are familiar to C programmers, such as those in the [[stdio.h|stdio]] family, are available in standard PHP builds.<ref>{{cite web|access-date=2015-01-14|url=https://php.net/manual/en/indexes.functions.php|title=PHP: Function and Method listing{{snd}} Manual |publisher=The PHP Group}}</ref>
PHP allows developers to write [[Software extension|extensions]] in [[C (programming language)|C]] to add functionality to the PHP language. PHP extensions can be compiled statically into PHP or loaded dynamically at runtime. Numerous 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]]. Other PHP features made available through extensions include integration with [[Internet Relay Chat]] (IRC), dynamic generation of images and [[Adobe Flash]] content, ''PHP Data Objects'' (PDO) as an abstraction layer used for accessing databases,<ref>{{cite web|url=http://www.php.net/manual/en/intro.pdo.php |title=Introduction{{snd}} Manual |website=php.net |date=2013-06-07 |access-date=2013-06-13}}</ref><ref>{{cite web|url=http://www.onlamp.com/pub/a/php/2004/08/05/dataobjects.html|title=Simplify Business Logic with PHP DataObjects — O'Reilly Media|author=Darryl Patterson|date=5 August 2004|website=ibm.com|access-date=16 December 2014|archive-date=16 December 2014|archive-url=https://web.archive.org/web/20141216140653/http://www.onlamp.com/pub/a/php/2004/08/05/dataobjects.html|url-status=dead}}</ref><ref>{{cite web|url=http://www-128.ibm.com/developerworks/db2/library/techarticle/dm-0612xia/|title=IBM — United States|access-date=16 December 2014}}</ref><ref>{{cite web|url=http://www-128.ibm.com/developerworks/library/os-php-dbmistake/index.html |title=Five common PHP database problems |website=ibm.com |date=2006-08-01 |access-date=2013-06-13}}</ref><ref>{{cite web|url=http://www.redbooks.ibm.com/abstracts/sg247218.html|title=IBM Redbooks — Developing PHP Applications for IBM Data Servers|website=redbooks.ibm.com|access-date=16 December 2014}}</ref><ref>{{cite web|url=http://www.phparch.com/issue.php?mid=65|title=php[architect] Magazine - The Journal for PHP Programmers|website=www.phparch.com}}</ref><ref>{{cite magazine|url=http://www.infoworld.com/article/05/10/19/HNphpshow_1.html|title=PHP catching on at enterprises, vying with Java|last=Krill|first=Paul|date=19 October 2005|magazine=InfoWorld|archive-url=https://web.archive.org/web/20140713004345/http://www.infoworld.com/d/developer-world/php-catching-enterprises-vying-java-708|archive-date=13 July 2014}}</ref> and even [[speech synthesis]]. Some of the language's core functions, such as those dealing with strings and arrays, are also implemented as extensions.<ref>{{cite web|url=http://lxr.php.net/xref/PHP_5_4/ext/standard/|archive-url=https://web.archive.org/web/20120316010914/http://lxr.php.net/xref/PHP_5_4/ext/standard/|url-status=dead|archive-date=16 March 2012|title=Cross Reference: /PHP_5_4/ext/standard/|website=php.net|access-date=16 December 2014}}</ref> The [[PHP Extension Community Library]] (PECL) project is a repository for extensions to the PHP language.<ref>{{cite web|access-date=2008-02-25|url=http://www.devnewz.com/090902b.html|title=Developing Custom PHP Extensions |website=devnewz.com |date=2002-09-09 |archive-url = https://web.archive.org/web/20080218045752/http://www.devnewz.com/090902b.html |archive-date = 2008-02-18}}</ref>
Some other projects, such as ''Zephir'', provide the ability for PHP extensions to be created in a high-level language and compiled into native PHP extensions. Such an approach, instead of writing PHP extensions directly in C, simplifies the development of extensions and reduces the time required for programming and testing.<ref>{{cite web
| url = http://docs.zephir-lang.com/en/latest/motivation.html
| title = Why Zephir?
| date = 2015-10-20 | access-date = 2015-12-14
| website = zephir-lang.com
}}</ref>
By December 2018 the PHP Group consisted of ten people: [[Thies C. Arntzen]], [[Stig Bakken]], [[Shane Caraveo]], [[Andi Gutmans]], [[Rasmus Lerdorf]], [[Sam Ruby]], [[Sascha Schumann]], [[Zeev Suraski]], [[Jim Winstead]], and [[Andrei Zmievski]].<ref>{{cite web|title=PHP Credits|url=https://php.net/credits|access-date=2018-12-16}}</ref>
[[Zend Technologies]] provides a [[Zend Certified Engineer|PHP Certification]] based on PHP 7<ref>{{Cite web|title=Learn PHP Via PHP Training and PHP Certification|url=https://www.zend.com/training/php|access-date=2020-11-16|website=www.zend.com}}</ref> exam (and previously based on PHP 5.5) for programmers to become certified PHP developers.
== The PHP Foundation ==
{{Infobox organization
| formation = {{start date and age|2021|11|22}}
| logo = The PHP Foundation Logo.svg
| founder = [[Automattic]], [[Laravel]], [[Acquia]], [[Zend]], Private Packagist, [[Symfony]], Craft CMS, Tideways, [[PrestaShop]], [[JetBrains]]<ref>{{Cite web |last=Walker |first=James |date=2021-12-13 |title=What the New PHP Foundation Means for PHP's Future |url=https://www.howtogeek.com/devops/what-the-new-php-foundation-means-for-phps-future/ |access-date=2023-11-26 |website=How-To Geek |language=en}}</ref>
| website = https://thephp.foundation
}}
On 26 November 2021, the [[JetBrains]] blog announced the creation of The PHP Foundation, which will sponsor the design and development of PHP.<ref>{{Cite web |title=The New Life of PHP – The PHP Foundation {{!}} The PhpStorm Blog |url=https://blog.jetbrains.com/phpstorm/2021/11/the-php-foundation/ |access-date=2022-06-16 |website=The JetBrains Blog |date=22 November 2021 |language=en-US}}</ref>
== <span id=PHPFPM>Installation and configuration</span> ==
[[File:PHP 7.1 - Example phpinfo() Screen.png|thumb|Example output of the phpinfo() function in PHP 7.1]]
There are two primary ways for adding support for PHP to a web server – as a native web server module, or as a CGI executable. PHP has a direct module interface called [[server application programming interface]] (SAPI), which is supported by many web servers including [[Apache HTTP Server]], [[Internet Information Services|Microsoft IIS]] and [[Oracle iPlanet Web Server|iPlanet Web Server]]. Some other web servers, such as OmniHTTPd, support the [[Internet Server Application Programming Interface]] (ISAPI), which is [[Microsoft]]'s web server module interface. If PHP has no module support for a web server, it can always be used as a [[Common Gateway Interface]] (CGI) or [[FastCGI]] processor; in that case, the web server is configured to use PHP's CGI executable to process all requests to PHP files.<ref name="installation">{{cite web
| url = http://www.php.net/manual/en/install.general.php
| title = General Installation Considerations
| access-date = 2013-09-22
| website = php.net
}}</ref>
PHP-FPM (FastCGI Process Manager) is an alternative FastCGI implementation for PHP, bundled with the official PHP distribution since version 5.3.3.<ref>{{cite web
| url = http://www.php.net/archive/2010.php#id2010-07-22-2
| title = News Archive: PHP 5.3.3 Released!
| date = 2010-07-22
| website = php.net}}</ref> When compared to the older FastCGI implementation, it contains some additional features, mostly useful for heavily loaded web servers.<ref>{{cite web
| url = http://www.php.net/manual/en/install.fpm.php
| title = FastCGI Process Manager (FPM)
| access-date = 2013-09-22
| website = php.net
}}</ref>
When using PHP for command-line scripting, a PHP [[command-line interface]] (CLI) executable is needed. PHP supports a CLI [[server application programming interface]] (SAPI) since PHP 4.3.0.<ref>{{cite web
| url = http://www.php.net/manual/en/features.commandline.introduction.php
| title = Command line usage: Introduction
| access-date = 2013-09-22
| website = php.net
}}</ref> The main focus of this SAPI is developing [[command line interface|shell]] applications using PHP. There are quite a few differences between the CLI SAPI and other SAPIs, although they do share many of the same behaviours.<ref>{{cite web
| url = http://www.php.net/manual/en/features.commandline.differences.php
| title = Command line usage: Differences to other SAPIs
| access-date = 2013-09-22
| website = php.net
}}</ref>
PHP has a direct module interface called SAPI for different web servers;<ref name="php-installation2">{{cite web
|url = https://php.net/manual/en/install.general.php|title = General Installation Considerations|access-date = 2013-09-22|website = php.net}}</ref> in case of PHP 5 and Apache 2.0 on Windows, it is provided in form of a [[Dynamic-link library|DLL]] file called {{Mono|php5apache2.dll}},<ref>{{cite web|url = https://php.net/manual/en/install.windows.apache2.php|title = PHP: Apache 2.x on Microsoft Windows|access-date = 2013-09-22|website = php.net|url-status = dead|archive-url = https://web.archive.org/web/20130926122011/http://php.net/manual/en/install.windows.apache2.php|archive-date = 2013-09-26}}</ref> which is a module that, among other functions, provides an interface between PHP and the web server, implemented in a form that the server understands. This form is what is known as a SAPI.{{Citation needed|date=November 2023}}
There are different kinds of SAPIs for various web server extensions. For example, in addition to those listed above, other SAPIs for the PHP language include the Common Gateway Interface and command-line interface.<ref name="php-installation2" /><ref>{{cite web
|url = http://www.php.net/manual/en/features.commandline.introduction.php|title = Command line usage: Introduction|access-date = 2013-09-22|website = php.net}}</ref>
PHP can also be used for writing desktop [[graphical user interface]] (GUI) applications, by using the [[PHP-GTK]] extension. PHP-GTK is not included in the official PHP distribution,<ref name="installation" /> and as an extension, it can be used only with PHP versions 5.1.0 and newer. The most common way of installing PHP-GTK is by compiling it from the source code.<ref>{{cite web
| url = http://gtk.php.net/manual/en/tutorials.installation.php
| title = Installing PHP-GTK 2
| access-date = 2013-09-22
| website = php.net
}}</ref>
When PHP is installed and used in [[Cloud computing|cloud]] environments, [[software development kit]]s (SDKs) are provided for using cloud-specific features.{{Citation needed|date=November 2023}} For example:
* [[Amazon Web Services]] provides the AWS SDK for PHP<ref>{{cite web|url=http://aws.amazon.com/sdkforphp/ |title=AWS SDK for PHP |website=aws.amazon.com |access-date=2014-03-06}}</ref>
* [[Microsoft Azure]] can be used with the Windows Azure SDK for PHP.<ref>{{cite web |url=http://www.interoperabilitybridges.com/projects/php-sdk-for-windows-azure.aspx |title=Windows Azure SDK for PHP — Interoperability Bridges and Labs Center |website=interoperabilitybridges.com |access-date=2014-03-06 |url-status=dead |archive-url=https://web.archive.org/web/20140320152702/http://www.interoperabilitybridges.com/projects/php-sdk-for-windows-azure.aspx |archive-date=2014-03-20 }}</ref>
Numerous configuration options are supported, affecting both core PHP features and extensions.<ref>{{cite web
| url = http://www.php.net/manual/en/configuration.php
| title = Runtime configuration: Table of contents
| access-date = 2013-09-22
| website = php.net
}}</ref><ref>{{cite web
| url = http://www.php.net/manual/en/ini.list.php
| title = php.ini directives: List of php.ini directives
| access-date = 2013-09-22
| website = php.net
}}</ref> Configuration file <code>php.ini</code> is searched for in different locations, depending on the way PHP is used.<ref>{{cite web
| url = http://www.php.net/manual/en/configuration.file.php
| title = Runtime configuration: The configuration file
| access-date = 2013-09-22
| publisher = PHP.net
}}</ref> The configuration file is split into various sections,<ref>{{cite web
| url = http://www.php.net/manual/en/ini.sections.php
| title = php.ini directives: List of php.ini sections
| access-date = 2013-09-22
| publisher = PHP.net
}}</ref> while some of the configuration options can be also set within the web server configuration.<ref>{{cite web
| url = http://www.php.net/manual/en/configuration.changes.modes.php
| title = Runtime configuration: Where a configuration setting may be set
| access-date = 2013-09-22
| publisher = PHP.net
}}</ref>
== Use ==
[[File:LAMP software bundle.svg|thumb|upright=2|A broad overview of the LAMP software bundle, displayed here together with [[Squid (software)|Squid]] ]]
PHP is a general-purpose scripting language that is especially suited to [[server-side scripting|server-side]] [[web development]], in which case PHP generally runs on a [[web server]]. Any PHP code in a requested file is [[execution (computing)|executed]] by the PHP runtime, usually to create [[dynamic web page]] content or dynamic images used on websites or elsewhere.<ref>{{cite web|url=https://php.net/manual/en/book.image.php |title=PHP Manual Image Processing and GD; |publisher= php.net |access-date=2011-04-09}}</ref> It can also be used for [[command-line]] scripting and [[client-side]] [[graphical user interface]] (GUI) applications. PHP can be deployed on most web servers, many [[operating system]]s and [[computing platform|platforms]], and can be used with many [[relational database management system]]s (RDBMS). Most [[web hosting]] providers support PHP for use by their clients. 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|access-date=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|archive-date=2008-02-19|archive-url=https://web.archive.org/web/20080219180226/http://www.onlamp.com/pub/a/php/2001/05/03/php_foundations.html|url-status=dead}}</ref>
[[File:Scheme dynamic page en.svg|thumb|upright=2|Dynamic web page: example of [[server-side scripting]] (PHP and MySQL)]]
Originally designed to create dynamic [[web page]]s, PHP now focuses mainly on [[server-side scripting]],<ref>{{cite web|url=http://webmaster.iu.edu/PHPlanguage/index.shtml|title=PHP Server-Side Scripting Language|publisher=[[Indiana University]]|access-date=2008-02-25|date=2007-04-04|archive-url=https://web.archive.org/web/20160121223739/http://webmaster.iu.edu/tools-and-guides/programming-languages/php.phtml|archive-date=2016-01-21}}</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 [[Python (programming language)|Python]], [[Microsoft]]'s [[ASP.NET]], [[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|access-date=2008-02-25}}</ref> and <code>[[mod_perl]]</code><!-- do not remove the underscore from mod_perl: it is part of the name -->. PHP has also attracted the development of many [[software framework]]s that provide building blocks and a design structure to promote [[rapid application development]] (RAD).{{Citation needed|date=November 2023}} Some of these include [[PRADO (framework)|PRADO]], [[CakePHP]], [[Symfony]], [[CodeIgniter]], [[Laravel]], [[Yii Framework]], [[Phalcon (framework)|Phalcon]] and [[Laminas]], offering features similar to other [[web framework]]s.
The [[LAMP (software bundle)|LAMP architecture]] has become popular in the web industry as a way of deploying web applications.<ref>{{cite web|url=http://www.ibm.com/developerworks/library/os-5waystunelamp/index.html|title=Five simple ways to tune your LAMP application| website=[[IBM]] |date=2011-01-25}}</ref> 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]], [[Perl]], or some mix of the three. Similar packages, [[WAMP (software bundle)|WAMP]] and [[MAMP]], are also available for [[Microsoft Windows|Windows]] and [[macOS]], with the first letter standing for the respective operating system. Although both PHP and Apache are provided as part of the macOS base install, users of these packages seek a simpler installation mechanism that can be more easily kept up to date.{{Citation needed|date=November 2023}}
For specific and more advanced usage scenarios, PHP offers a well-defined and documented way for writing custom extensions in [[C (programming language)|C]] or [[C++]].<ref>{{cite web
| url = http://www.php.net/manual/en/internals2.structure.php
| title = PHP at the core: Extension structure
| access-date = 2013-09-22
| website = PHP.net
}}</ref><ref>{{cite web
| url = http://www.php.net/manual/en/internals2.counter.php
| title = PHP at the core: The "counter" Extension – A Continuing Example
| access-date = 2013-09-22
| website = PHP.net
}}</ref><ref>{{cite web
| url = http://devzone.zend.com/303/extension-writing-part-i-introduction-to-php-and-zend/
| title = Extension Writing Part I: Introduction to PHP and Zend
| date = 2005-03-01
| access-date = 2013-09-22
| publisher = [[Zend Technologies]]
| archive-url = https://web.archive.org/web/20130924233638/http://devzone.zend.com/303/extension-writing-part-i-introduction-to-php-and-zend/
| archive-date = 2013-09-24
| url-status = dead
}}</ref><ref>{{cite web
| url = http://devzone.zend.com/317/extension-writing-part-ii-parameters-arrays-and-zvals/
| title = Extension Writing Part II: Parameters, Arrays, and ZVALs
| date = 2005-06-06
| access-date = 2013-09-22
| publisher = [[Zend Technologies]]
| archive-url = https://web.archive.org/web/20130926091658/http://devzone.zend.com/317/extension-writing-part-ii-parameters-arrays-and-zvals/
| archive-date = 2013-09-26
| url-status = dead
}}</ref><ref>{{cite web
| url = http://devzone.zend.com/318/extension-writing-part-ii-parameters-arrays-and-zvals-continued/
| title = Extension Writing Part II: Parameters, Arrays, and ZVALs (continued)
| date = 2005-06-06
| access-date = 2013-09-22
| publisher = [[Zend Technologies]]
| archive-url = https://web.archive.org/web/20130926091655/http://devzone.zend.com/318/extension-writing-part-ii-parameters-arrays-and-zvals-continued/
| archive-date = 2013-09-26
| url-status = dead
}}</ref><ref>{{cite web
| url = http://devzone.zend.com/446/extension-writing-part-iii-resources/
| title = Extension Writing Part III: Resources
| date = 2006-05-12
| access-date = 2013-09-22
| publisher = [[Zend Technologies]]
| archive-url = https://web.archive.org/web/20130926091645/http://devzone.zend.com/446/extension-writing-part-iii-resources/
| archive-date = 2013-09-26
| url-status = dead
}}</ref><ref>{{cite web
| url = http://devzone.zend.com/1435/wrapping-c-classes-in-a-php-extension/
| title = Wrapping C++ Classes in a PHP Extension
| date = 2009-04-22
| access-date = 2013-09-22
| publisher = [[Zend Technologies]]
| archive-url = https://web.archive.org/web/20130920011549/http://devzone.zend.com/1435/wrapping-c-classes-in-a-php-extension/
| archive-date = 2013-09-20
| url-status = dead
}}</ref>{{Primary source inline|date=November 2023|reason=Since this is a broad generalization, secondary sources are required}} Besides extending the language itself in form of additional [[Library (computing)|libraries]], extensions are providing a way for improving execution speed where it is critical and there is room for improvements by using a true [[compiled language]].<ref>{{cite web
| url = https://stackoverflow.com/q/1110682
| title = Extending PHP with C++?
| access-date = 2013-09-22
| publisher = [[Stack Overflow]]
}}</ref><ref>{{cite web
| url = https://stackoverflow.com/q/1502244
| title = How can I use C++ code to interact with PHP?
| access-date = 2013-09-22
| publisher = [[Stack Overflow]]
}}</ref> PHP also offers well-defined ways for embedding itself into other software projects. That way PHP can be easily used as an internal [[scripting language]] for another project, also providing tight interfacing with the project's specific internal [[data structure]]s.<ref>{{cite book
| title = Extending and Embedding PHP
| first = Sara | last = Golemon
| year = 2006
| publisher = Sams | isbn = 978-0-672-32704-9
}}</ref>
PHP received mixed reviews due to lacking support for [[Multithreading (software)|multithreading]] at the core language level,<ref>{{cite web
| url = https://bugs.php.net/bug.php?id=46919
| title = Request #46919: Multithreading
| access-date = 2013-09-22
| website = PHP.net
}}</ref> though using threads is made possible by the "pthreads" [[PHP Extension Community Library|PECL]] extension.<ref>{{cite web
| url = http://www.php.net/manual/en/intro.pthreads.php
| title = pthreads: Introduction (PHP Manual)
| access-date = 2013-09-22
| website = PHP.net
}}</ref><ref>{{cite web|url=https://pecl.php.net/package/pthreads |title=PECL :: Package :: pthreads |website=pecl.php.net |access-date=2014-02-09}}</ref>
A command line interface, php-cli, and two [[ActiveX]] [[Windows Script Host]] scripting engines for PHP have been produced.{{Citation needed|date=November 2023}}
=== Popularity and usage statistics ===
{{Pie chart
|radius = 160
<!-- PHP version 8 (26.5%) -->
|value1 = 0.56 <!-- Formula: Version 8.3 is used by 2.1% of all the websites who use PHP version 8, so 26.5 / 100 * 2.1 = 0.56 -->
|label1 = PHP 8.3: 2.10% of PHP 8
|color1 = #66FF66
|value2 = 4.85
|label2 = PHP 8.2: 18.3% of PHP 8
|color2 = #D4F4B4
|value3 = 10.79
|label3 = PHP 8.1: 40.7% of PHP 8
|color3 = #FEF8C6
|value4 = 10.31
|label4 = PHP 8.0: 38.9% of PHP 8
|color4 = #FDB3AB
<!-- PHP version 7 (57.2%) -->
|value5 = 39.47 <!-- Formula: Version 7.4 is used by 69% of all the websites who use PHP version 7, so 57.2 / 100 * 69 = 39.47 -->
|label5 = PHP 7.4: 69.0% of PHP 7
|color5 = red
|value6 = 7.55
|label6 = PHP 7.3: 13.2% of PHP 7
|color6 = MediumVioletRed
|value7 = 5.49
|label7 = PHP 7.2: 9.60% of PHP 7
|color7 = PaleVioletRed
|value8 = 2.23
|label8 = PHP 7.1: 3.90% of PHP 7
|color8 = IndianRed
|value9 = 2.46
|label9 = PHP 7.0: 4.30% of PHP 7
|color9 = DarkRed
<!-- PHP version 5 (16.2%) -->
|value10 = 8.7480
|label10 = PHP 5.6: 54.0% of PHP 5
|color10 = LightGrey
|value11 = 1.3608
|label11 = PHP 5.5: 8.40% of PHP 5
|color11 = DarkGrey
|value12 = 2.4948
|label12 = PHP 5.4: 15.4% of PHP 5
|color12 = Grey
|value13 = 2.4138
|label13 = PHP 5.3: 14.9% of PHP 5
|color13 = DimGrey
|value14 = 1.1016
|label14 = PHP 5.2: 6.80% of PHP 5
|color14 = LightSlateGrey
|value15 = 0.0648
|label15 = PHP 5.1: 0.40% of PHP 5
|color15 = SlateGrey
|value16 = 0.0162
|label16 = PHP 5.0: 0.10% of PHP 5
|color16 = DarkSlateGrey
<!-- PHP version 4 (0.2%) -->
|value17 = 0.1574
|label17 = PHP 4.4: 78.7% of PHP 4
|color17 = Violet
|value18 = 0.0370
|label18 = PHP 4.3: 18.5% of PHP 4
|color18 = BlueViolet
|value19 = 0.0032
|label19 = PHP 4.2: 1.60% of PHP 4
|color19 = DarkViolet
|value20 = 0.0016
|label20 = PHP 4.1: 0.80% of PHP 4
|color20 = DarkBlue
|value21 = 0.0006
|label21 = PHP 4.0: 0.30% of PHP 4
|color21 = Black
|caption = Usage share of PHP versions on {{Date|2024-03-23}}:<br> four months after PHP 8.3's release<ref name="PHP Usage Stats" /><ref>{{Cite web|url=https://w3techs.com/technologies/details/pl-php/4|title=Usage Statistics and Market Share of PHP Version 4 for Websites, March 2024|website=w3techs.com}}</ref><ref name="5 for Websites">{{Cite web|url=https://w3techs.com/technologies/details/pl-php/5|title=Usage Statistics and Market Share of PHP Version 5 for Websites, March 2024|website=w3techs.com}}</ref><ref>{{Cite web|url=https://w3techs.com/technologies/details/pl-php/7|title=Usage Statistics and Market Share of PHP Version 7 for Websites, March 2024|website=w3techs.com}}</ref><ref>{{Cite web|url=https://w3techs.com/technologies/details/pl-php/8|title=Usage Statistics and Market Share of PHP Version 8 for Websites, march 2024|website=w3techs.com}}</ref>
}}
PHP is used for [[Web content management system]]s including [[MediaWiki]],<ref>{{cite web|date=2010-01-25|title=Manual:Installation requirements#PHP|url=http://www.mediawiki.org/w/index.php?title=Manual:Installation_requirements&oldid=299556#PHP|access-date=2010-02-26|publisher=MediaWiki|quote=PHP is the programming language in which MediaWiki is written [...]}}</ref> [[WordPress]],<ref>{{cite web|title=About WordPress|url=http://wordpress.org/about/|access-date=2010-02-26|quote=WordPress was [...] built on PHP}}</ref> [[Joomla]],<ref>{{cite web|last=Kempkens|first=Alex|title=Joomla! — Content Management System to build websites & apps|url=http://www.joomla.org/about-joomla.html}}</ref> [[Drupal]],<ref>{{cite web|title=PHP and Drupal|date=16 September 2007|url=http://drupal.org/node/176052|access-date=2010-06-13|publisher=Drupal.org}}</ref> [[Moodle]],<ref>{{cite web|title=About|url=http://docs.moodle.org/en/About_Moodle|access-date=2009-12-20|publisher=Moodle.org}}</ref> [[eZ Publish]], [[eZ Platform]], and [[SilverStripe]].<ref>{{cite web|title=Server requirements of SilverStripe|url=http://doc.silverstripe.org/framework/en/installation/server-requirements|url-status=dead|archive-url=https://web.archive.org/web/20141128063118/http://doc.silverstripe.org/framework/en/installation/server-requirements|archive-date=28 November 2014|access-date=13 October 2014|quote=SilverStripe requires PHP 5.3.2+}}</ref>
{{As of|2013|1}}, PHP was used in more than 240 million [[website]]s (39% of those sampled) and was installed on 2.1 million [[web server]]s.<ref>{{cite web | url=http://news.netcraft.com/archives/2013/01/31/php-just-grows-grows.html | title=PHP just grows & grows | date=2013-01-31 | access-date=2013-04-01 | author=Ide, Andy}}</ref>
{{As of|2024|03|23}} (four months after PHP 8.3's release), PHP is used as the server-side programming language on 76.4% of websites where the language could be determined; PHP 7 is the most used version of the language with 57.2% of websites using PHP being on that version, while 26.6% use PHP 8, 16.2% use PHP 5 and 0.2% use PHP 4.<ref name="PHP Usage Stats">{{cite web |title=Usage statistics of PHP for websites |url=https://w3techs.com/technologies/details/pl-php |website=W3Techs – World Wide Web Technology Surveys |publisher=W3Techs |access-date=23 March 2024}}</ref>
== <span id="REGISTER-GLOBALS">Security</span> ==
In 2019, 11% of all vulnerabilities listed by the [[National Vulnerability Database]] were linked to PHP;<ref name="CVE">{{cite web | url=https://nvd.nist.gov/vuln/search/statistics?form_type=Basic&results_type=statistics&query=PHP&queryType=phrase&search_type=all | title=National Vulnerability Database (NVD) Search Vulnerabilities Statistics | access-date=2019-11-22}}</ref> historically, about 30% of all vulnerabilities listed since 1996 in this database are linked to PHP. Technical security flaws of the language itself or of its core libraries are not frequent (22 in 2009, about 1% of the total although PHP applies to about 20% of programs listed).<ref name="PHP-related vulnerabilities on the National Vulnerability Database">{{cite web
| url=http://www.coelho.net/php_cve.html
| title=PHP-related vulnerabilities on the National Vulnerability Database
| date=2012-07-05
| access-date=2013-04-01
}}</ref> Recognizing that programmers make mistakes, some languages include [[taint checking]] to automatically detect the lack of [[data validation|input validation]] which induces many issues. Such a feature is being developed for PHP,<ref>{{Cite web|url=https://wiki.php.net/rfc/taint|title=PHP: rfc:taint|website=wiki.php.net}}</ref> but its inclusion into a release has been rejected several times in the past.<ref>{{cite web
| url=http://derickrethans.nl/files/meeting-notes.html#sand-boxing-or-taint-mode <!-- formerly at https://php.net/~derick/meeting-notes.html#sand-boxing-or-taint-mode -->
| title=Developer Meeting Notes, Nov. 2005}}</ref><ref>{{cite web
|url = http://devzone.zend.com/article/2798-Zend-Weekly-Summaries-Issue-368#Heading1
|title = Taint mode decision, November 2007
|url-status = dead
|archive-url = https://web.archive.org/web/20090226124957/http://devzone.zend.com/article/2798-Zend-Weekly-Summaries-Issue-368#Heading1
|archive-date = 2009-02-26
}}</ref>
There are advanced protection patches such as [[Suhosin]] and [[hardening (computing)|Hardening]]-Patch, specially designed for web hosting environments.<ref>{{cite web
| title=Hardened-PHP Project
| url=http://www.hardened-php.net
| date=2008-08-15
| access-date=2019-08-22
| archive-url=https://web.archive.org/web/20190224012812/http://www.hardened-php.net/
| archive-date=2019-02-24
| url-status=dead
}}</ref>
Historically, old versions of PHP had some configuration parameters and default values for such runtime settings that made some PHP applications prone to security issues. Among these, <code>[[magic quotes|magic_quotes_gpc]]</code> and <code>register_globals</code><ref name="register-globals">{{cite web
| url = https://php.net/manual/en/security.globals.php
| title = Security: Using Register Globals | work = PHP Manual
| access-date = 2013-09-22
| publisher = PHP.net
}}</ref> configuration directives were the best known; the latter made any URL parameters become PHP variables, opening a path for serious security vulnerabilities by allowing an attacker to set the value of any uninitialized global variable and interfere with the execution of a PHP script. Support for "[[magic quotes]]" and "register globals" settings has been deprecated since PHP 5.3.0, and removed from PHP 5.4.0.<ref name="magic-quotes">{{cite web
| url = http://www.php.net/manual/en/security.magicquotes.php
| title = Magic Quotes | work = PHP Manual
| access-date = 2014-01-17
| publisher = PHP.net
}}</ref>
Another example for the potential runtime-settings vulnerability comes from failing to disable PHP execution (for example by using the <code>engine</code> configuration directive)<ref>{{cite web
| url = http://www.php.net/manual/en/apache.configuration.php#ini.engine
| title = 'engine' configuration directive
| work = PHP: Runtime Configuration
| access-date = 2014-02-13
| publisher = PHP.net
}}</ref> for the directory where uploaded files are stored; enabling it can result in the execution of malicious code embedded within the uploaded files.<ref>{{cite web
| url = http://devzone.zend.com/1008/php-security-exploit-with-gif-images/
| title = PHP Security Exploit With GIF Images
| date = 2007-06-22
| access-date = 2013-09-22
| archive-url = https://web.archive.org/web/20130927162421/http://devzone.zend.com/1008/php-security-exploit-with-gif-images/
| archive-date = 2013-09-27
| url-status = dead
}}</ref><ref>{{cite web
| url = http://www.phpclasses.org/blog/post/67-PHP-security-exploit-with-GIF-images.html
| title = PHP security exploit with GIF images
| date = 2007-06-20 | access-date = 2013-09-22
| publisher = PHP Classes blog
}}</ref><ref>{{cite web
|url = http://ha.ckers.org/blog/20070604/passing-malicious-php-through-getimagesize/
|title = Passing Malicious PHP Through getimagesize()
|date = 2007-06-04
|access-date = 2013-09-22
|url-status = dead
|archive-url = https://web.archive.org/web/20130921222424/http://ha.ckers.org/blog/20070604/passing-malicious-php-through-getimagesize
|archive-date = 2013-09-21
}}</ref> The best practice is to either locate the image directory outside of the document root available to the web server and serve it via an intermediary script or disable PHP execution for the directory which stores the uploaded files.{{Citation needed|date=November 2023}}
Also, enabling the dynamic loading of PHP extensions (via <code>enable_dl</code> configuration directive)<ref>{{cite web
| url = http://www.php.net/manual/en/info.configuration.php#ini.enable-dl
| title = 'enable_dl' configuration directive
| work = PHP: Runtime Configuration
| access-date = 2014-02-13
| publisher = PHP.net
}}</ref> in a [[shared web hosting]] environment can lead to security issues.<ref>{{cite web
| url = https://php.net/manual/en/function.dl.php
| title = PHP function reference: dl()
| access-date = 2013-09-22
| publisher = PHP.net
}}</ref><ref>{{cite web
| url = http://www.webhostingtalk.com/showthread.php?t=514779
| title = My host won't fix their Trojan
| access-date = 2013-09-22
| publisher = WebHosting Talk
}}</ref>
Implied [[type conversion]]s that result in different values being treated as equal, sometimes against the programmer's intent, can lead to security issues. For example, the result of the comparison {{nowrap|1=<code>'0e1234' == '0'</code>}} is <code>true</code>, because strings that are parsable as numbers are converted to numbers; in this case, the first compared value is treated as [[scientific notation]] having the value ({{val|0|e=1234}}), which is zero. Errors like this resulted in authentication vulnerabilities in [[Simple Machines Forum]],<ref>{{cite web|url=http://raz0r.name/vulnerabilities/simple-machines-forum/|title= Simple Machines Forum <= 2.0.3 Admin Password Reset|author=Raz0r|date = 25 January 2013}}</ref> [[Typo3]]<ref>{{cite web|url=http://blog.nibblesec.org/2010/12/typo3-sa-2010-020-typo3-sa-2010-022.html|title=TYPO3-SA-2010-020, TYPO3-SA-2010-022 EXPLAINED|author=Nibble Security}}</ref> and [[phpBB]]<ref>{{cite web|url=http://ahack.ru/articles/cryptographic-security-and-php-applications.htm |title=Криптостойкость и небезопасное сравнение |website=Ahack.ru |language=ru }}</ref> when [[MD5]] [[password hashing|password hashes]] were compared. The recommended way is to use [https://secure.php.net/hash_equals hash_equals()] (for [[timing attack]] safety), <code>[[strcmp]]</code> or the identity operator (<code>===</code>), as {{nowrap|1=<code>'0e1234' === '0'</code>}} results in <code>false</code>.<ref>{{cite web|url=https://www.php.net/manual/en/language.operators.comparison.php |title=Comparison operators |publisher=PHP.net}}</ref>
In a 2013 analysis of over 170,000 [[website defacement]]s, published by [[Zone-H]], the most frequently (53%) used technique was the exploitation of [[file inclusion vulnerability]], mostly related to insecure usage of the PHP language constructs <code>include</code>, <code>require</code>, and <code>allow_url_fopen</code>.<ref>{{cite web | url=https://ipsec.pl/web-application-security/most-common-attacks-web-applications.html | title=Most common attacks on web applications | publisher=IPSec.pl | date=2013 | access-date=2015-04-15 | first=Pawel |last=Krawczyk | archive-url=https://web.archive.org/web/20150415150236/https://ipsec.pl/web-application-security/most-common-attacks-web-applications.html | archive-date=2015-04-15 | url-status=dead }}</ref><ref>{{cite web | url=https://ipsec.pl/application-security/2013/so-what-are-most-critical-application-flaws-new-owasp-top-10.html | title=So what are the "most critical" application flaws? On new OWASP Top 10 | publisher=IPSec.pl | date=2013 | access-date=2015-04-15 |first=Pawel |last=Krawczyk }}</ref>
{{As of|2024|03|23|post=,}} (4 months after PHP 8.3 release) W3Techs reports that 83.9% of websites using PHP, use versions 8.0 or older (which are [[End-of-life (product)#Computing|no longer supported]] by The PHP Development Team).<ref>{{Cite web|url=https://w3techs.com/technologies/details/pl-php/all/all|title=Usage Statistics and Market Share of PHP for Websites, March 2024|website=w3techs.com|access-date=2024-03-23}}</ref> PHP Version 5 is still used by 16.2% of all websites.<ref name="5 for Websites"/> It is highly recommended to migrate to PHP 8.1 or later and use <code>random_int()</code><ref>{{cite web | url=https://php.net/random_int | title=PHP: Random_int - Manual }}</ref> instead of <code>rand()</code><ref>{{cite web | url=https://php.net/rand | title=PHP: Rand - Manual }}</ref> or <code>mt_rand()</code>,<ref>{{cite web | url=https://php.net/mt_rand | title=PHP: Mt_rand - Manual }}</ref> as the latter functions are not cryptographically secure. There are two attacks that can be performed over PHP entropy sources: "seed attack" and "state recovery attack".{{Citation needed|date=November 2023}} With current{{when|date=March 2023}} GPU technologies, an attacker can perform up to 2{{sup|30}} MD5 calculations per second with a $250 GPU, while with an additional $500 can reach up to 2{{sup|32}} calculations.<ref>{{Cite web|url=https://www.readkong.com/page/i-forgot-your-password-randomness-attacks-against-php-2199669|title=I Forgot Your Password: Randomness Attacks Against PHP Applications|website=www.readkong.com}}</ref> In combination with a "[[birthday attack]]" this can lead to serious security vulnerabilities.{{Citation needed|date=November 2023}}
== See also ==
{{Portal|Computer programming|Free and open-source software}}
{{Div col|colwidth=25em}}
* [[Comparison of programming languages]]
* [[List of Apache–MySQL–PHP packages]]
* [[List of PHP accelerators]]
* [[List of PHP editors]]
* [[PEAR]] (PHP Extension and Application Repository)
* [[PHP accelerator]]
* [[Template processor]]
* [[XAMPP]] (free and open-source cross-platform web server solution stack package)
* [[Zend Server]]
{{div col end}}
== References ==
{{Reflist}}
== Further reading ==
{{Spoken Wikipedia|En-PHP.ogg|date=2011-11-23}}
* {{cite journal |quote=What's the Absolute Minimum I Must Know About PHP? |url= https://www.bloomberg.com/graphics/2015-paul-ford-what-is-code/ |title=What is Code? |first=Paul |last=Ford |date=June 11, 2015 |journal=[[Bloomberg Businessweek]]}}
==External links==
* {{Official website}}
* {{Curlie|Computers/Programming/Languages/PHP}}
{{Navboxes|list=
{{PHP}}
{{Web interfaces}}
{{Programming languages}}
{{FOSS}}
}}
{{Sister bar|wikt=no|commons=Category:PHP|v=Topic:PHP|n=no|q=no|s=no|b=PHP Programming|voy=no|mw=PHP}}
{{Authority control}}
[[Category:PHP| ]]
[[Category:1995 software]]
[[Category:Articles with example PHP code]]
[[Category:Class-based programming languages]]
[[Category:Cross-platform software]]
[[Category:Dynamic programming languages]]
[[Category:Dynamically typed programming languages]]
[[Category:Filename extensions]]
[[Category:Free compilers and interpreters]]
[[Category:High-level programming languages]]
[[Category:Internet terminology]]
[[Category:Object-oriented programming languages]]
[[Category:PHP software]]
[[Category:Procedural programming languages]]
[[Category:Programming languages]]
[[Category:Programming languages created in 1995]]
[[Category:Scripting languages]]
[[Category:Software using the PHP license]]
[[Category:Text-oriented programming languages]]' |
New page wikitext, after the edit (new_wikitext ) | '{{Short description|Scripting language created in 1994}}
{{About|the scripting language}}
{{Infobox programming language
| logo = PHP-logo.svg
| file ext = {{codes|.php|.phar|.phtml|.pht|.phps|d=,}}
| paradigm = [[Multi-paradigm programming language|Multi-paradigm]]: [[imperative programming|imperative]], [[functional programming|functional]], [[object-oriented programming|object-oriented]], [[procedural programming|procedural]], [[reflective programming|reflective]]
| released = {{start date and age|1995|06|08|df=y}}<ref name="history-php-release" /><ref name="mysqlconference">{{cite web | last=Lerdorf | first=Rasmus | title=PHP on Hormones – history of PHP presentation by Rasmus Lerdorf given at the MySQL Conference in Santa Clara, California | date=2007-04-26 | access-date=2009-12-11 | publisher=The Conversations Network | url=http://itc.conversationsnetwork.org/shows/detail3298.html | archive-date=2019-01-06 | archive-url=https://web.archive.org/web/20190106230504/http://web.archive.org/web/20130729204354id_/http://itc.conversationsnetwork.org/shows/detail3298.html | url-status=dead }}</ref>
| designer = [[Rasmus Lerdorf]]
| developer = {{URL|https://php.net/credits/|The PHP Development Team}}, [[Zend Technologies]], {{URL|https://thephp.foundation/|PHP Foundation}}
| latest release version = 8.3.4
| latest release date = {{Start date and age|2024|03|14|df=y}}<ref>{{Cite web|url=https://www.php.net/archive/2024.php#2024-03-14-2|title=PHP: News Archive - 2024|website=www.php.net}}</ref>
| latest preview version =
| latest preview date =
| typing = [[Dynamic typing|Dynamic]], [[Strong and weak typing|weak]], [[Gradual typing|gradual]]<ref>{{cite web|url=https://secure.php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration.strict|title=PHP: Function arguments – Manual|website=secure.php.net}}</ref>
| implementations = [[Zend Engine]], [[HHVM]], [[PeachPie]], [[Quercus (software)|Quercus]], [[Parrot virtual machine|Parrot]]
| dialects =
| influenced by = [[Perl]], [[C (programming language)|C]], [[C++]], [[Java (programming language)|Java]],<ref>{{cite web | url = https://www.php.net/manual/en/preface.php | title = PHP: Preface – Manual}}</ref> [[Tcl]],<ref name="mysqlconference" /> [[JavaScript]]<ref name="optimisation ideas">{{Cite tweet |user=dstogov |number=672864802474229760 |last=Stogov |first=Dmitry |date = 2015-12-04 |title=It's not a secret that some #PHP7 optimization ideas came from HHVM, LuaJIT and V8. Thank you @HipHopVM @SaraMG. #php7thankyou}}</ref>
| influenced = [[Hack (programming language)|Hack]], [[Jakarta Server Pages|JSP]], [[Active Server Pages|ASP]], [[React (software)|React JS]]
| programming language = [[C (programming language)|C]] (primarily; some components [[C++]])
| operating system = [[Unix-like]], [[Windows]], [[macOS]], [[IBM i]], [[OpenVMS]]
| license = dual licensed [[GNU General Public License]] version 2 or any later version and PHP License for PHP versions 3.0 or earlier.<ref>{{cite web |title=PHP: Release Archives (museum) |url=https://museum.php.net/php3/ |website=museum.php.net}}</ref> Only [[PHP License]] (most of Zend engine under [[Zend Engine License]]) for 3.01x and later versions.
| website = {{Official URL}}
| wikibooks = PHP Programming
}}
'''PHP''' is a [[general-purpose programming language|general-purpose]] [[scripting language]] geared towards [[web development]].<ref>{{Cite web|url=https://www.php.net/|title=PHP: Hypertext Preprocessor|website=www.php.net|access-date=2020-02-12}}</ref> It was originally created by Danish-Canadian [[programmer]] [[Rasmus Lerdorf]] in 1993 and released in 1995.<ref name=":0">{{Cite web |last=Krill |first=Paul |date=2013-11-18 |title=Believe the hype: PHP founder backs Facebook's HipHop technology |url=https://www.infoworld.com/article/2609877/believe-the-hype--php-founder-backs-facebook-s-hiphop-technology.html |access-date=2022-10-13 |website=InfoWorld |language=en}}</ref><ref>{{Cite web |title=Announce: Personal Home Page Tools (PHP Tools) |url=https://groups.google.com/g/comp.infosystems.www.authoring.cgi/c/PyJ25gZ6z7A/m/M9FkTUVDfcwJ?pli=1 |access-date=2022-11-03 |website=groups.google.com}}</ref> The PHP [[reference implementation]] is now produced by the PHP Group.<ref name="about PHP">{{cite web|access-date=2008-02-25|url=https://www.php.net/history|title=History of PHP and related projects |publisher=The PHP Group}}</ref> PHP was originally an abbreviation of '''''Personal Home Page''''',<ref name="History of PHP">{{cite web |title=History of PHP |url=https://php.net/manual/en/history.php.php |website=php.net}}</ref><ref>{{Cite book |last=Olsson |first=Mikael |url=https://books.google.com/books?id=_ahBAAAAQBAJ |title=PHP Quick Scripting Reference |date=2013-09-04 |publisher=Apress |isbn=978-1-4302-6284-8 |language=en}}</ref> but it now stands for the [[recursive initialism]] '''''PHP: Hypertext Preprocessor'''''.<ref>[https://php.net/manual/en/preface.php PHP Manual: Preface], www.php.net.</ref>
PHP code is usually processed on a [[web server]] by a PHP [[interpreter (computing)|interpreter]] implemented as a [[plugin (computing)|module]], a [[daemon (computing)|daemon]] or a [[Common Gateway Interface]] (CGI) executable. On a web server, the result of the [[interpreter (computing)|interpreted]] and executed PHP code{{em dash}}which may be any type of data, such as generated [[HTML]] or [[binary number|binary]] image data{{em dash}}would form the whole or part of an [[HTTP]] response. Various [[web template system]]s, web [[content management system]]s, and [[web framework]]s exist that can be employed to orchestrate or facilitate the generation of that response. Additionally, PHP can be used for many programming tasks outside the web context, such as standalone [[graphical user interface|graphical applications]]<ref>{{cite web | url = https://php.net/manual/en/intro-whatcando.php | work = PHP Manual | title = Introduction: What can PHP do? | access-date = 2009-03-05}}</ref> and [[unmanned aerial vehicle|drone]] control.<ref>{{Citation|title=helicopter: Port of node-ar-drone which allows user to control a Parrot AR Drone over PHP: jolicode/php-ar-drone|date=2019-01-11|url=https://github.com/jolicode/php-ar-drone|publisher=JoliCode|access-date=2019-02-23}}</ref> PHP code can also be directly executed from the [[command-line interface|command line]].
The standard PHP interpreter, powered by the [[Zend Engine]], is [[free software]] released under the [[PHP License]]. PHP has been widely ported and can be deployed on most web servers on a variety of [[operating system]]s and [[computing platform|platforms]].<ref name="foundations" />
The PHP language has evolved without a written [[formal specification]] or standard<!-- until 2014-->, with the original [[implementation]] acting as the ''[[de facto]]'' standard that other implementations aimed to follow. <!-- PHP standard spec dropped at Github, besides would have been on old EOLed version of PHP: Since 2014, work has gone on to create a formal PHP specification.<ref>{{cite web|last1=Jackson|first1=Joab|title=PHP gets a formal specification, at last|url=https://www.computerworld.com/article/2490649/php-gets-a-formal-specification--at-last.html|website=Computerworld|publisher=[[International Data Group|IDG]]|date=2014-07-31}}</ref> -->
W3Techs reports that {{as of|2024|03|23|lc=y}} (the four months after the PHP 8.3 release), PHP is used by 76.4% of all websites whose programming language could be determined, and 57.2% thereof use PHP 7 which is outdated and known to be insecure.<ref name="PHP Usage Stats" /> Additionally, <!-- the most used version of 8.x, --> PHP 8.0, is no longer supported,<ref>{{Cite web |title=Usage Statistics and Market Share of PHP Version 8 for Websites, March 2024 |url=https://w3techs.com/technologies/details/pl-php/8 |access-date=2024-03-23 |website=w3techs.com}}</ref> meaning the vast majority of PHP users utilize outdated versions, and well over half of all websites, PHP-using or not (whose programming language could be determined) are insecure.<!-- this part detailed described in "Security" section, may be is better to remove it from here -->
== History ==
{{multiple image
| align = right
| width = 105
| image1 = Rasmus Lerdorf cropped.jpg
| image2 = Andi Gutmans 1.jpg
| image3 = Zeev Suraski 2005 cropped.jpg
| footer = [[Rasmus Lerdorf]], creator of PHP; and [[Andi Gutmans]] and [[Zeev Suraski]], creators of the [[Zend Engine]]
}}
=== Early history ===
PHP development began in 1993<ref name=":0" /> when [[Rasmus Lerdorf]] wrote several [[Common Gateway Interface]] (CGI) programs in [[C-programming|C]],<ref name="php_origins">{{cite web | url = https://twitter.com/rasmus/status/226405807305138176 | title = I wonder why people keep writing that PHP was ever written in Perl. It never was. #php | last = Lerdorf | first = Rasmus | publisher = Twitter | date = 2012-07-20 | access-date = 2014-09-04}}</ref><ref>{{cite web | url = http://itc.conversationsnetwork.org/shows/detail3298.html | title = PHP on Hormones | format = mp3 | last = Lerdorf | first = Rasmus | publisher = The Conversations Network | date = 2007-04-26 | access-date = 2009-06-22 | archive-date = 2019-01-06 | archive-url = https://web.archive.org/web/20190106230504/http://web.archive.org/web/20130729204354id_/http://itc.conversationsnetwork.org/shows/detail3298.html | url-status = dead }}</ref> which he used to maintain his [[personal homepage]]. He extended them to work with [[web form]]s and to communicate with [[database]]s, and called this implementation "Personal Home Page/Forms Interpreter" or PHP/FI.
An example of the early PHP [[Syntax (programming languages)|syntax]]:<ref>{{cite web|last=Lerdorf|first=Rasmus|year=2007|title=Slide 3|url=http://talks.php.net/show/mysql07key/3|access-date=2009-06-22|work=slides for 'PHP on Hormones' talk|publisher=The PHP Group}}
</ref>
<syntaxhighlight lang="PHP">
<!--include /text/header.html-->
<!--getenv HTTP_USER_AGENT-->
<!--if substr $exec_result Mozilla-->
Hey, you are using Netscape!<p>
<!--endif-->
<!--sql database select * from table where user='$username'-->
<!--ifless $numentries 1-->
Sorry, that record does not exist<p>
<!--endif exit-->
Welcome <!--$user-->!<p>
You have <!--$index:0--> credits left in your account.<p>
<!--include /text/footer.html-->
</syntaxhighlight>
PHP/FI could be used to build simple, [[dynamic web application]]s. To accelerate [[software bug|bug]] reporting and improve the code, Lerdorf initially announced the release of PHP/FI as "Personal Home Page Tools (PHP Tools) version 1.0" on the [[Usenet]] discussion group ''comp.infosystems.www.authoring.cgi'' on 8 June 1995.<ref name="history-php-release">{{cite web|url= https://groups.google.com/group/comp.infosystems.www.authoring.cgi/msg/cc7d43454d64d133?pli=1 |title=Announce: Personal Home Page Tools (PHP Tools)|last=Lerdorf|first=Rasmus|date=June 8, 1995|access-date=7 June 2011}}</ref><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 = https://groups.google.com/group/comp.infosystems.www.authoring.cgi/msg/cc7d43454d64d133 | access-date = 2006-09-17}}</ref> This release included basic functionality such as [[Local variable#Local variables in Perl|Perl-like variables]], form handling, and the ability to embed [[HTML]]. By this point, the [[syntax]] had changed to resemble that of [[Perl]], but was simpler, more limited, and less consistent.<ref name="History of PHP" /><ref name="about PHP" />
Early PHP was never intended to be a new [[Programming language theory|programming language]]; rather, it grew organically, with Lerdorf noting in retrospect: "I don't know how to stop it [...] there was never any intent to write a programming language [...] I have absolutely no idea how to write a programming language [...] I just kept adding the next logical step on the way."<ref name=itconversations>{{cite web|title = Rasmus Lerdorf, Senior Technical Yahoo: PHP, Behind the Mic|date = 2003-11-19|url =http://itc.conversationsnetwork.org/shows/detail58.html|archive-url = https://web.archive.org/web/20130728125152/http://itc.conversationsnetwork.org/shows/detail58.html|archive-date = 2013-07-28}}</ref> A development team began to form and, after months of work and [[Beta development stage|beta]] testing, officially released PHP/FI 2 in November 1997<ref>{{Cite web |last1=Alshetwi |first1=A.B. |last2=Rahmat |first2=R. A. A. O. |last3=Borhan |first3=M. N. |last4=Ismael |first4=S. |last5=Ali |first5=A. |last6=Irtema |first6=H. I. M. |last7=Alfakhria |first7=A. Y. |date=2018 |title=Web-Based Expert System for Optimizing of Traffic Road in Developing Countries |url=https://www.researchgate.net/publication/326727672 |access-date=13 Feb 2024}}</ref>.{{Citation needed|date=November 2023}}
The fact that PHP was not originally designed, but instead was developed organically has led to inconsistent naming of functions and inconsistent ordering of their parameters.<ref>{{cite web|title=Problems with PHP|url=http://toykeeper.net/soapbox/php_problems/|access-date=20 December 2010}}</ref> In some cases, the function names were chosen to match the lower-level libraries which PHP was "wrapping",<ref>{{cite web|url=http://news.php.net/php.internals/70950 |title=php.internals: Re: Function name consistency |website=news.php.net |date=2013-12-28 |access-date=2014-02-09}}</ref> while in some very early versions of PHP the length of the function names was used internally as a [[hash function]], so names were chosen to improve the distribution of [[hash values]].<ref name="php-internals-70691">{{cite newsgroup |title=Re: Flexible function naming |author=[[Rasmus Lerdorf]] |date=Dec 16, 2013 |newsgroup=php.internals |url=http://news.php.net/php.internals/70691 |access-date=December 26, 2013}}</ref>
=== PHP 3 and 4 ===
[[File:Custom-software-developement-php-net.JPG|thumb|This is an example of PHP code for the [[WordPress]] [[content management system]].]]
[[Zeev Suraski]] and [[Andi Gutmans]] rewrote the [[parser]] in 1997 and formed the base of PHP 3, changing the language's name to the [[recursive acronym]] ''PHP: Hypertext Preprocessor''.<ref name="about PHP" /><ref>{{cite web|title=PHP{{snd}} Acronym Meaning Vote |url=http://il.php.net/vote_listing.php3 |website=PHP.net |archive-date=August 15, 2000 |url-status=dead |archive-url=https://web.archive.org/web/20000815063125/http://il.php.net/vote_listing.php3}}</ref> 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 | access-date = 2006-09-17 | archive-url = https://web.archive.org/web/20060719204721/http://www.zend.com/zend/zend-engine-summary.php | archive-date = 2006-07-19 | url-status = dead}}</ref> They also founded [[Zend Technologies]] in [[Ramat Gan]], [[Israel]].<ref name="about PHP" />
On 22 May 2000, PHP 4, powered by the Zend Engine 1.0, was released.<ref name="about PHP" /> By August 2008, this branch had reached version 4.4.9. PHP 4 is now no longer under development and nor are any security updates planned to be released.<ref name="2007 news">{{cite web|title=php.net 2007 news archive|url=https://www.php.net/archive/2007.php|publisher=The PHP Group|access-date=2008-02-22|date=2007-07-13}}</ref><ref>{{cite web |access-date=2018-12-16 |url=https://www.internetnews.com/developer/php-4-is-dead%ef%bf%bdlong-live-php-5/|title=PHP 4 is Dead—Long Live PHP 5 |publisher=InternetNews |date=2008-02-01 |last=Kerner |first=Sean Michael |archive-url=https://web.archive.org/web/20180806115411/http://www.internetnews.com/dev-news/article.php/3725291 |archive-date=2018-08-06}}</ref>
=== PHP 5 ===
On 1 July 2004, PHP 5 was released, powered by the new Zend Engine II.<ref name="about PHP" /> PHP 5 included new features such as improved support for [[object-oriented programming]], the PHP Data Objects (PDO) 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|access-date=2008-02-22|date=2004-07-15|author=Trachtenberg, Adam|archive-date=2016-03-31|archive-url=https://web.archive.org/web/20160331232050/http://www.onlamp.com/pub/a/php/2004/07/15/UpgradePHP5.html|url-status=dead}}</ref> In 2008, PHP 5 became the only stable version under development. [[Late static binding]] had been missing from previous versions of PHP, and was added in version 5.3.<ref>{{cite web|url=http://www.digitalsandwich.com/archives/53-Late-Static-Binding-in-PHP.html|access-date=2008-03-25|title=Late Static Binding in PHP|date=2006-02-23|publisher=Digital Sandwich}}</ref><ref>{{cite web|access-date=2008-03-25|url=https://www.php.net/language.oop5.static|title=Static Keyword|publisher=The PHP Group}}</ref>
Many high-profile open-source projects ceased to support PHP 4 in new code from February 5, 2008, because of the GoPHP5 initiative,<ref name="gophp5_projects">{{cite web | url=http://www.gophp5.org/projects|title=GoPHP5 | url-status=dead | archive-url=https://web.archive.org/web/20110717133313/http://gophp5.org/projects | archive-date=2011-07-17}}</ref> 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 |access-date=2008-02-23 |work=GoPHP5 Press Release | url-status=dead | archive-url=https://web.archive.org/web/20190804012720/http://gophp5.org/sites/gophp5.org/files/press_release.pdf | archive-date=2019-08-04}}</ref><ref>{{cite web|url=http://gophp5.org/|title=GoPHP5|publisher=GoPHP5|access-date=2008-02-22 | url-status=dead | archive-url=https://web.archive.org/web/20110427101913/http://www.gophp5.org/ | archive-date=2011-04-27}}</ref>
Over time, PHP interpreters became available on most existing [[32-bit]] and [[64-bit]] operating systems, either by building them from the PHP source code or by using pre-built binaries.<ref>{{cite web
| url = https://www.php.net/manual/en/install.php
| title = PHP Installation and Configuration
| access-date = 2013-10-29
| website = php.net
}}</ref> For PHP versions 5.3 and 5.4, the only available [[Microsoft Windows]] binary distributions were 32-bit [[IA-32]] builds,<ref>{{cite web
| url = https://windows.php.net/download/#php-5.3
| title = PHP for Windows: Binaries and sources releases (5.3)
| access-date = 2013-10-29
| website = php.net
}}</ref><ref>{{cite web
| url = https://windows.php.net/download/#php-5.4
| title = PHP for Windows: Binaries and sources releases (5.4)
| access-date = 2013-10-29
| website = php.net
}}</ref> requiring Windows 32-bit compatibility mode while using [[Internet Information Services]] (IIS) on a 64-bit Windows platform. PHP version 5.5 made the 64-bit [[x86-64]] builds available for Microsoft Windows.<ref>{{cite web
| url = https://windows.php.net/download/#php-5.5
| title = PHP for Windows: Binaries and sources releases (5.5)
| access-date = 2013-10-29
| website = php.net
}}</ref>
Official security support for PHP 5.6 ended on 31 December 2018.<ref>{{Cite web | url=https://php.net/supported-versions.php |title = PHP: Supported Versions}}</ref>
=== <span id="PHP6-UNICODE">PHP 6 and Unicode</span> ===
PHP received mixed reviews due to lacking native [[Unicode]] support at the core language level.<ref>{{cite web
| url = https://php.net/manual/en/language.types.string.php
| title = Types: Strings (PHP Manual)
| access-date = 2013-09-22
| website = PHP.net
}}</ref><ref>{{cite web
| url = https://www.php.net/manual/en/language.types.string.php#language.types.string.details
| title = Details of the String Type (PHP Manual)
| access-date = 2021-09-22
| website = PHP.net
}}</ref> In 2005, a project headed by Andrei Zmievski was initiated to bring native [[Unicode]] support throughout PHP, by embedding the [[International Components for Unicode]] (ICU) library, and representing text strings as [[UTF-16]] internally.<ref>{{cite mailing list|url=http://marc.info/?l=php-internals&m=112365908921757&w=1|title=PHP Unicode support design document|date=2005-08-10|access-date=2014-02-09|author=Andrei Zmievski}}</ref> Since this would cause major changes both to the internals of the language and to user code, it was planned to release this as version 6.0 of the language, along with other major features then in development.<ref>{{cite web|url=http://news.php.net/php.internals/17668|title=PHP 5.5 or 6.0|access-date=2014-02-09}}</ref>
However, a shortage of developers who understood the necessary changes, and performance problems arising from conversion to and from UTF-16, which is rarely used in a web context, led to delays in the project.<ref>{{cite web|title=The Good, the Bad, and the Ugly: What Happened to Unicode and PHP 6|url=http://www.slideshare.net/andreizm/the-good-the-bad-and-the-ugly-what-happened-to-unicode-and-php-6|access-date=2014-02-09|author=Andrei Zmievski|date=2011-04-22}}</ref> As a result, a PHP 5.3 release was created in 2009, with many non-Unicode features back-ported from PHP 6, notably namespaces. In March 2010, the project in its current form was officially abandoned, and a PHP 5.4 release was prepared to contain most remaining non-Unicode features from PHP 6, such as traits and closure re-binding.<ref>{{cite mailing list|url=http://news.php.net/php.internals/47120|title=PHP 6|access-date=2014-02-07|date=2010-03-11|author=Rasmus Lerdorf}}</ref> Initial hopes were that a new plan would be formed for Unicode integration, but by 2014 none had been adopted.{{Citation needed|date=November 2023}}
=== PHP 7 ===
During 2014 and 2015, a new major PHP version was developed, PHP 7. The numbering of this version involved some debate among internal developers.<ref>{{cite web|url=https://philsturgeon.uk/php/2014/07/23/neverending-muppet-debate-of-php-6-v-php-7/|title=The Neverending Muppet Debate of PHP 6 v PHP 7|access-date=2015-11-19|archive-url=https://web.archive.org/web/20151119132438/https://philsturgeon.uk/php/2014/07/23/neverending-muppet-debate-of-php-6-v-php-7/|archive-date=2015-11-19|url-status=dead}}</ref> While the PHP 6 Unicode experiments had never been released, several articles and book titles referenced the PHP 6 names, which might have caused confusion if a new release were to reuse the name.<ref>{{cite web |title=RFC: Name of Next Release of PHP |url=https://wiki.php.net/rfc/php6 |date=2014-07-07 |access-date=2014-07-15 |website=php.net}}</ref> After a vote, the name PHP 7 was chosen.<ref>{{cite web|title=Re: [PHP-DEV] [VOTE] [RFC] Name of Next Release of PHP (again) |url=https://www.mail-archive.com/internals@lists.php.net/msg68598.html |date=2014-07-30 |access-date=2014-07-30}}</ref>
The foundation of PHP 7 is a PHP [[branching (version control)|branch]] that was originally dubbed ''PHP next generation'' (''phpng''). It was authored by Dmitry Stogov, Xinchen Hui and Nikita Popov,<ref>{{cite web|url=http://news.php.net/php.internals/73888|title=phpng: Refactored PHP Engine with Big Performance Improvement|website=news.php.net}}</ref> and aimed to optimize PHP performance by refactoring the Zend Engine while retaining near-complete language compatibility.<ref>{{cite web |url=https://wiki.php.net/rfc/phpng |title=PHP: rfc:phpng |access-date=16 December 2014 |website=php.net}}</ref> By 14 July 2014, [[WordPress]]-based benchmarks, which served as the main benchmark suite for the phpng project, showed an almost 100% increase in performance. Changes from phpng make it easier to improve performance in future versions, as more compact data structures and other changes are seen as better suited for a successful migration to a [[Just-in-time compilation|just-in-time]] (JIT) compiler.<ref name="phpng">{{cite web|url=https://wiki.php.net/phpng |title=PHP: phpng |website=php.net |access-date=2014-07-15}}</ref> Because of the significant changes, the reworked Zend Engine was called ''Zend Engine 3'', succeeding Zend Engine 2 used in PHP 5.<ref name="ZE2">{{cite web |url=https://github.com/php/php-src/commit/150dc69d6eee35738f505e925ee664c02060196d |website=github.com |date=2014-12-05 |access-date=2014-12-05 |title=Merge branch 'ZendEngine3'}}</ref>
Because of the major internal changes in phpng, it must receive a new [[Software versioning|major version]] number of PHP, rather than a minor PHP 5 release, according to PHP's release process.<ref name="releaseprocess" /> Major versions of PHP are allowed to break backward-compatibility of code and therefore PHP 7 presented an opportunity for other improvements beyond phpng that require backward-compatibility breaks.{{Citation needed|date=November 2023}} In particular, it involved the following changes:
* Many fatal or recoverable-level legacy PHP error mechanisms were replaced with modern object-oriented [[Exception (computer science)|exceptions]].<ref name="engine_exceptions" />
* The syntax for variable dereferencing was reworked to be internally more consistent and complete, allowing the use of the operators <code>-></code>, <code>[]</code>, <code>()</code>,<code>{}</code>, and <code>::</code>, with arbitrary meaningful left-side expressions.<ref name="uvs">{{cite web |url=https://wiki.php.net/rfc/uniform_variable_syntax |title=PHP RFC: Uniform Variable Syntax |date=2014-05-31 |access-date=2014-07-30 |website=php.net}}</ref>
* Support for legacy PHP 4-style constructor methods was deprecated.<ref>{{Cite web|url=https://3v4l.org/udRhX|title=Online PHP editor | output for udRhX|website=3v4l.org}}</ref>
* The behavior of the [[foreach loop|<code>foreach</code> statement]] was changed to be more predictable.<ref>{{cite web|url=https://wiki.php.net/rfc/php7_foreach|title=PHP RFC: Fix "foreach" behavior|access-date=2015-05-21|website=php.net}}</ref>
* Constructors for the few classes built-in to PHP which returned null upon failure were changed to throw an exception instead, for consistency.<ref>{{cite web|url=https://wiki.php.net/rfc/internal_constructor_behaviour|title=PHP RFC: Constructor behaviour of internal classes|access-date=2015-05-21|website=php.net}}</ref>
* Several unmaintained or deprecated [[server application programming interface]]s (SAPIs) and extensions were removed from the PHP core, most notably the legacy <code>mysql</code> extension.<ref>{{cite web|url=https://wiki.php.net/rfc/removal_of_dead_sapis_and_exts|title=PHP RFC: Removal of dead or not yet PHP7 ported SAPIs and extensions|access-date=2015-05-21|website=php.net}}</ref>
* The behavior of the <code>list()</code> operator was changed to remove support for strings.<ref>{{cite web|url=https://wiki.php.net/rfc/fix_list_behavior_inconsistency|title=PHP RFC: Fix list() behavior inconsistency|access-date=2015-05-21|website=php.net}}</ref>
* Support was removed for legacy ASP-style delimiters <code><%</code> and <code>%></code> and <code><script language="php"> ... </script></code>.<ref>{{cite web|url=https://wiki.php.net/rfc/remove_alternative_php_tags|title=PHP RFC: Remove alternative PHP tags|access-date=2015-05-21|website=php.net}}</ref>
* An oversight allowing a [[switch statement]] to have multiple <code>default</code> clauses was fixed.<ref>{{cite web|url=https://wiki.php.net/rfc/switch.default.multiple|title=PHP RFC: Make defining multiple default cases in a switch a syntax error|access-date=2015-05-21|website=php.net}}</ref>
* Support for hexadecimal number support in some implicit conversions from strings to number types was removed.<ref>{{cite web|url=https://wiki.php.net/rfc/remove_hex_support_in_numeric_strings|title=PHP RFC: Remove hex support in numeric strings|access-date=2015-05-21|website=php.net}}</ref>
* The [[left-shift operator|left-shift]] and [[right-shift operator|right-shift]] operators were changed to behave more consistently across platforms.<ref name="integer_semantics" />
* Conversions between floating-point numbers and integers were changed (e.g. infinity changed to convert to zero) and implemented more consistently across platforms.<ref name="integer_semantics">{{cite web|url=https://wiki.php.net/rfc/integer_semantics|title=PHP RFC: Integer Semantics|access-date=2015-05-21|quote=Making NaN and Infinity always become zero when cast to integer means more cross-platform consistency, and is also less surprising than what is currently produces|website=php.net}}</ref><ref>{{cite web|url=https://wiki.php.net/rfc/zpp_fail_on_overflow|title=PHP RFC: ZPP Failure on Overflow|access-date=2015-05-21|website=php.net}}</ref>
PHP 7 also included new language features. Most notably, it introduced return type declarations for functions<ref name="return-types">{{cite web |url=https://wiki.php.net/rfc/return_types |title=RFC: Return Types |date=2015-01-27 |access-date=2015-01-28 |website=php.net}}</ref> which complement the existing parameter type declarations, and support for the [[Variable (computer science)|scalar]] types (integer, float, string, and boolean) in parameter and return type declarations.<ref name="scalar-types">{{cite web|url=https://wiki.php.net/rfc/scalar_type_hints_v5|title=RFC: Scalar Type Declarations |date=2015-03-16 |access-date=2015-03-17 |website=php.net}}</ref>
=== PHP 8 ===
PHP 8 was released on 26 November 2020, and is currently the second-most used PHP major version. PHP 8 is a major version and has breaking changes from previous versions.<ref name="new-in-php8">{{cite web |author=Brent |title=What's new in PHP 8 |url=https://stitcher.io/blog/new-in-php-8 |website=Stitcher |access-date=22 September 2020}}</ref><ref name="PHP-8-Released">{{cite web |title=PHP 8 Released|url=https://www.php.net/releases/8.0/en.php |website=PHP |access-date=27 November 2020}}</ref> New features and notable changes include:
==== Just-in-time compilation ====
[[Just-in-time compilation]] is supported in PHP 8.<ref name="php-8-JIT" />
PHP 8's [[just-in-time compilation|JIT compiler]] can provide substantial performance improvements for some use cases,<ref name="php-jit-performance-in-web-apps">{{cite web |author=Brent |title=PHP 8: JIT performance in real-life web applications |url=https://stitcher.io/blog/jit-in-real-life-web-applications |website=Stitcher.io |access-date=4 October 2020}}</ref><ref>{{cite web |last1=Rethams |first1=Derick |title=PHP 8: A Quick Look at JIT |url=https://derickrethans.nl/a-quick-look-at-jit.html}}</ref> while PHP developer Nikita Popov stated that the performance improvements for most websites will be less substantial than the upgrade from PHP 5 to PHP 7.<ref name="php-8-nikita-popov" /> Substantial improvements are expected more for mathematical-type operations than for common web-development use cases.<ref name="php-8-nikita-popov">{{cite web |last1=Popov |first1=Nikita |title="What's new in PHP 8.0?" Nikita Popov |url=https://www.youtube.com/watch?v=NbBRXwu1Md8 |archive-url=https://ghostarchive.org/varchive/youtube/20211211/NbBRXwu1Md8| archive-date=2021-12-11 |url-status=live|publisher=PHP fwdays |access-date=4 October 2020}}{{cbignore}}</ref> Additionally, the JIT compiler provides the future potential to move some code from C to PHP, due to the performance improvements for some use cases.<ref name="kinsta-php-8-changes">{{cite web |last1=Daniele |first1=Carlo |title=What's New in PHP 8 (Features, Improvements, and the JIT Compiler) |url=https://kinsta.com/blog/php-8/ |website=Kinsta |date=25 May 2020 |access-date=24 December 2020}}</ref>
==== Addition of the match expression ====
{{Main|PHP syntax and semantics#Match expression}}
PHP 8 introduced the {{code|match}} expression.<ref name="match-statement-php-8-laravel-news">{{cite web |last1=Redmond |first1=Paul |title=Match Expression is Coming to PHP 8 |url=https://laravel-news.com/match-expression-php-8 |website=Laravel News |date=15 July 2020 |access-date=4 October 2020}}</ref> The match expression is conceptually similar to a {{code|switch}} statement and is more compact for some use cases.<ref name="php-watch-match-statements-php-8">{{cite web |title=PHP 8.0: Match Expressions |url=https://php.watch/versions/8.0/match-expression |website=PHP Watch |access-date=4 October 2020}}</ref> Because {{code|match}} is an expression, its result can be assigned to a variable or returned from a function.<ref>{{cite web |last1=Barnes |first1=Eric |title=PHP 8 is now Released! |url=https://laravel-news.com/php-8 |website=Laravel News |date=27 November 2020 |access-date=24 December 2020 |ref=laravel-news-php-8-released}}</ref>
==== Type changes and additions ====
PHP 8 introduced union types, a new {{code|static}} return type, and a new {{code|mixed}} type.<ref name="new-in-php8" />
"Attributes", often referred to as "annotations" in other programming languages, were added in PHP 8, which allow metadata to be added to classes.<ref name="new-in-php8" />
{{code|throw}} was changed from being a statement to being an expression.<ref name="throw-expression-php8" /> This allows exceptions to be thrown in places that were not previously possible.<ref name="new-in-php8" />
==== Syntax changes and additions ====
PHP 8 includes changes to allow alternate, more concise, or more consistent syntaxes in a number of scenarios. For example, the nullsafe operator is similar to the [[null coalescing operator]] {{code|??}}, but used when calling methods.<ref name="nullsafe-operator-rfc" /> The following code snippet will not throw an error if {{code|getBirthday()}} returns null:
<syntaxhighlight lang="php">
$human_readable_date = $user->getBirthday()?->diffForHumans();
</syntaxhighlight>
Constructor property promotion has been added as "[[syntactic sugar]]," allowing class properties to be set automatically when parameters are passed into a class [[Constructor (object-oriented programming)|constructor]].<ref name="new-in-php8" /> This reduces the amount of [[boilerplate code]] that must be written.{{Citation needed|date=November 2023}}
Other minor changes include support for use of {{code|::class}} on objects, which serves as an alternative for the use of {{code|get_class()}};<ref name="new-in-php8" /> non-capturing catches in try-catch blocks; variable syntax tweaks to resolve inconsistencies; support for named arguments; and support for trailing commas in parameter lists, which adds consistency with support for trailing commas in other contexts, such as in arrays.{{Citation needed|date=November 2023}}
==== Standard library changes and additions ====
* Weak maps were added in PHP 8. A {{code|WeakMap}} holds references to objects, but these references do not prevent such objects from being [[Garbage collection (computer science)|garbage collected]].<ref name="php-8-weak-refs" /> This can provide performance improvements in scenarios where data is being [[Cache (computing)|cached]]; this is of particular relevance for [[object–relational mapping]]s (ORM).<ref name="new-in-php8" />
* Various adjustments to interfaces, such as adding support for creating {{code|DateTime}} objects from interfaces, and the addition of a {{code|Stringable}} interface that can be used for type hinting.{{Citation needed|date=November 2023}}
* Various new functions including str_contains(), str_starts_with(), and str_ends_with();<ref name="new-string-functions-php-8">{{cite web |last1=Merchant |first1=Amit |title=These new string functions are coming in PHP 8 |url=https://www.amitmerchant.com/new-string-functions-php8/ |website=Amit Merchant |date=13 June 2020 |access-date=4 October 2020}}</ref> fdiv(); get_debug_type(); and get_resource_id(){{Citation needed|date=November 2023}}
* Object implementation of token_get_all(){{Citation needed|date=November 2023}}
==== Additional changes ====
* Type annotations were also added into PHP's C source code itself to allow internal functions and methods to have "complete type information in reflection."<ref>{{cite web |last1=Popov |first1=Nikita |title=Call for participation: Annotating internal function argument and return types |url=https://externals.io/message/106522 |website=Externals |access-date=19 November 2020}}</ref>
* Inheritance with private methods{{Citation needed|date=November 2023}}
* Abstract methods in traits improvements{{Citation needed|date=November 2023}}
=== PHP 8.1 ===
PHP 8.1 was released on November 25, 2021.<ref>{{Cite web|url=https://www.php.net/ChangeLog-8.php#8.1.0 |title=PHP 8 ChangeLog |access-date=2024-01-05 |website=PHP.net}}</ref> It added support for [[enumerated type|enumerations]] (also called "enums"), declaring properties as <code>readonly</code> (which prevents modification of the property after initialization), and array unpacking with string keys. The new [[bottom type|never type]] can be used to indicate that a function does not return.<ref>{{Cite web|title=PHP: PHP 8.1.0 Release Announcement |url=https://www.php.net/releases/8.1/en.php |access-date=2024-01-05 |website=PHP.net}}</ref>
=== PHP 8.2 ===
PHP 8.2 was released on December 8, 2022.<ref>{{Cite web|url=https://www.php.net/ChangeLog-8.php#8.2.0 |title=PHP 8 ChangeLog |access-date=2024-01-05 |website=PHP.net}}</ref> New in this release are <code>readonly</code> classes (whose instance properties are implicitly readonly), [[disjunctive normal form]] (DNF) types, and the <code>random</code> extension, which provides a [[pseudorandom number generator]] with an object-oriented [[API]].<ref>{{Cite web|title=PHP: PHP 8.2.0 Release Announcement |url=https://www.php.net/releases/8.2/en.php |access-date=2024-01-05 |website=PHP.net}}</ref>
=== Release history ===
<!-- Template:Version - for version & release history. Documentation and examples: http://en.wikipedia.org/wiki/Template:Version -->
{| class="wikitable
|-
! Version
! style="min-width: 10em;" | Release date
! style="min-width: 10em;" | Supported until<ref name="eol">{{cite web|url=https://php.net/eol.php |title=Unsupported Branches |website=php.net |access-date=2019-07-31}}</ref>
! Notes
|-
| {{Version |o | 1.0}}
| 8 June 1995
|
| Officially called "Personal Home Page Tools (PHP Tools)". This is the first use of the name "PHP".<ref name="about PHP" />
|-
| {{Version |o | 2.0}}
| 1 November 1997
|
| Officially called "PHP/FI 2.0". This is the first release that could actually be characterised as PHP, being a standalone language with many features that have endured to the present day.
|-
| {{Version |o | 3.0}}
| 6 June 1998
| 20 October 2000<ref name="eol" />
| Development moves from one person to multiple developers. Zeev Suraski and Andi Gutmans rewritten the base for this version.<ref name="about PHP" />
|-
| {{Version |o | 4.0}}
| 22 May 2000<ref>{{cite web |title=PHP 4.0.0 Released |url=https://news-web.php.net/php.announce/22 |access-date=25 October 2020}}</ref>
| 23 June 2001<ref name="eol" />
| 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=https://www.php.net/ChangeLog-4.php|publisher=The PHP Group|access-date=2008-02-22|date=2008-01-03}}</ref>
|-
| {{Version |o | 4.1}}
| 10 December 2001<ref>{{cite web |title=PHP 4.1.0 Release Announcement |url=https://www.php.net/releases/4_1_0.php |access-date=25 October 2020}}</ref>
| 12 March 2002<ref name="eol" />
| Introduced "superglobals" ({{code|lang=php|$_GET}}, {{code|lang=php|code=$_POST}}, {{code|lang=php|code=$_SESSION}}, etc.)<ref name="php4changelog" />
|-
| {{Version |o | 4.2}}
| 22 April 2002<ref>{{cite web |title=PHP 4.2.0 Release Announcement |url=https://www.php.net/releases/4_2_0.php |access-date=25 October 2020}}</ref>
| 6 September 2002<ref name="eol" />
| Disabled <code>register_globals</code> 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" />
|-
| {{Version |o | 4.3}}
| 27 December 2002<ref>{{cite web |title=PHP 4.3.0 Release Announcement |url=https://www.php.net/releases/4_3_0.php |access-date=25 October 2020}}</ref>
| 31 March 2005<ref name="eol" />
| Introduced the [[command-line interface]] (CLI), to supplement the CGI.<ref name="php4changelog" /><ref name="phpclidocs">{{cite web|title= Using PHP from the command line | work = PHP Manual|url=https://php.net/manual/en/features.commandline.php|publisher=The PHP Group|access-date=2009-09-11}}</ref>
|-
| {{Version |o | 4.4}}
| 11 July 2005<ref>{{cite web |title=PHP 4.4.0 Release Announcement |url=https://www.php.net/releases/4_4_0.php |access-date=25 October 2020}}</ref>
| 7 August 2008<ref name="eol" />
| Fixed a memory corruption bug, which required breaking binary compatibility with extensions compiled against PHP version 4.3.x.<ref name="php44announcement">{{cite web|title=PHP 4.4.0 Release Announcement|work=PHP Mannual|url=https://php.net/releases/4_4_0.php|publisher=The PHP Group|access-date=2013-11-24}}</ref>
|-
| {{Version |o | 5.0}}
| 13 July 2004<ref>{{cite web |title=PHP 5.0.0 Released! |url=https://news-web.php.net/php.announce/50 |access-date=25 October 2020}}</ref>
| 5 September 2005<ref name="eol" />
| Zend Engine II with a new object model.<ref name="php5changelog">{{cite web|title=PHP: PHP 5 ChangeLog|url=https://www.php.net/ChangeLog-5.php|publisher=The PHP Group|access-date=2008-02-22|date=2007-11-08}}</ref>
|-
| {{Version |o | 5.1}}
| 24 November 2005<ref>{{cite web |title=PHP 5.1.0 Release Announcement |url=https://www.php.net/releases/5_1_0.php |access-date=25 October 2020}}</ref>
| 24 August 2006<ref name="eol" />
| Performance improvements with the introduction of compiler variables in re-engineered PHP Engine.<ref name="php5changelog" /> Added PHP Data Objects (PDO) as a consistent interface for accessing databases.<ref name="phpPdoDocs">{{cite web|title=PHP manual: PDO|url=https://php.net/manual/en/intro.pdo.php|publisher=The PHP Group|access-date=2011-11-15|date=2011-11-15}}</ref>
|-
| {{Version |o | 5.2}}
| 2 November 2006<ref>{{cite web |title=PHP 5.2.0 Release Announcement |url=https://www.php.net/releases/5_2_0.php |access-date=25 October 2020}}</ref>
| 6 January 2011<ref name="eol" />
| Enabled the filter extension by default. Native [[JSON]] support.<ref name="php5changelog" />
|-
| {{Version |o | 5.3}}
| 30 June 2009<ref>{{cite web |title=PHP 5.3.0 Release Announcement |url=https://www.php.net/releases/5_3_0.php |access-date=25 October 2020}}</ref>
| 14 August 2014<ref name="eol" />
| [[Namespace]] support; [[name binding|late static bindings]], jump label (limited [[goto]]), [[anonymous function]]s, [[closure (computer programming)|closures]], PHP archives (phar), [[garbage collection (computer science)|garbage collection]] for circular references, improved [[Microsoft Windows|Windows]] support, sqlite3, mysqlnd as a replacement for libmysql as the underlying library for the extensions that work with [[MySQL]], fileinfo as a replacement for mime_magic for better [[MIME]] support, the Internationalization extension, and deprecation of ereg extension.
|-
| {{Version |o | 5.4}}
| 1 March 2012<ref>{{cite web |title=PHP 5.4.0 Release Announcement |url=https://www.php.net/releases/5_4_0.php |access-date=25 October 2020}}</ref>
| 3 September 2015<ref name="eol" />
| [[trait (computer programming)|Trait]] support, short array syntax support. Removed items: <code>register_globals</code>, <code>safe_mode</code>, <code>allow_call_time_pass_reference</code>, {{code|lang=php|code=session_register()}}, {{code|lang=php|code=session_unregister()}} and {{code|lang=php|code=session_is_registered()}}. Built-in web server.<ref>{{cite web|url=https://php.net/manual/en/features.commandline.webserver.php |title=Built-in web server |access-date=March 26, 2012}}</ref> Several improvements to existing features, performance and reduced memory requirements.
|-
| {{Version |o | 5.5}}
| 20 June 2013<ref>{{cite web |title=PHP 5.5.0 Release Announcement |url=https://www.php.net/releases/5_5_0.php |access-date=25 October 2020}}</ref>
| 10 July 2016<ref name="supportedversions">{{cite web|url=https://php.net/supported-versions.php |title=Supported Versions |website=php.net |access-date=2017-12-13}}</ref>
| Support for [[generator (computer programming)|generators]], <code>finally</code> blocks for exceptions handling, OpCache (based on Zend Optimizer+) bundled in official distribution.<ref name="55changes">{{cite web|title=PHP 5.5.0 changes|url=https://php.net/manual/en/migration55.new-features.php|access-date=2015-03-03|website=php.net}}</ref>
|-
| {{Version |o | 5.6}}
| 28 August 2014<ref>{{cite web |title=PHP 5.6.0 Release Announcement |url=https://www.php.net/releases/5_6_0.php |access-date=25 October 2020}}</ref>
| 31 December 2018<ref name="supportedversions"/>
| Constant scalar expressions, [[variadic function]]s, argument unpacking, new exponentiation operator, extensions of the <code>use</code> statement for functions and constants, new <code>phpdbg</code> debugger as a SAPI module, and other smaller improvements.<ref name="56changes">{{cite web |title=Migrating from PHP 5.5.x to PHP 5.6.x |url=https://www.php.net/manual/en/migration56.new-features.php |access-date=2014-03-24 |website=php.net}}</ref>
|-
| style="background:silver;"| 6.x
| {{n/a|Not released}}
| {{n/a}}
| Abandoned version of PHP that planned to include native Unicode support.<ref>{{cite web|url=https://lwn.net/Articles/379909/|title=Resetting PHP 6|quote=There have been books on the shelves purporting to cover PHP 6 since at least 2008. But, in March 2010, the PHP 6 release is not out{{snd}} in fact, it is not even close to out. Recent events suggest that PHP 6 will not be released before 2011{{snd}} if, indeed, it is released at all.}}</ref><ref>{{cite web|url=http://www.infoworld.com/article/2841561/php/php-7-moves-full-speed-ahead.html|title=PHP 7 moves full speed ahead|quote=Recent versions of PHP have been part of the 5.x release series, but there will be no PHP 6. "We're going to skip [version] 6, because years ago, we had plans for a 6, but those plans were very different from what we're doing now," Gutmans said. Going right to version 7 avoids confusion.|date=2014-10-31}}</ref>
|-
| {{Version |o | 7.0}}
| 3 December 2015<ref name=php7final>{{cite web |url=https://php.net/archive/2018.php#id2018-07-19-2|title=News Archive – 2018: PHP 7.2.9 Released |date=2018-08-16 |access-date=2018-08-16 |website=php.net}}</ref>
| 10 January 2019<ref name="releaseprocess" />
| Zend Engine 3 (performance improvements<ref name="phpng" /> and 64-bit integer support on Windows<ref>{{cite web|url=https://wiki.php.net/rfc/size_t_and_int64_next|title=PHP: rfc:size_t_and_int64_next|website=php.net|access-date=16 December 2014}}</ref>), uniform variable syntax,<ref name="uvs" /> [[Abstract Syntax Tree|AST]]-based compilation process,<ref>{{cite web|url=https://wiki.php.net/rfc/abstract_syntax_tree|title=PHP: rfc:abstract_syntax_tree|website=php.net|access-date=16 December 2014}}</ref> added {{code|lang=php|code=Closure::call()}},<ref>{{cite web|url=https://wiki.php.net/rfc/closure_apply|title=PHP: rfc:closure_apply|website=php.net|access-date=16 December 2014}}</ref> bitwise shift consistency across platforms,<ref>{{cite web|url=https://wiki.php.net/rfc/integer_semantics|title=PHP: rfc:integer_semantics|website=php.net|access-date=16 December 2014}}</ref> {{code|lang=php|code=??}} ([[Null coalescing operator|null coalesce]]) operator,<ref>{{cite web|url=https://wiki.php.net/rfc/isset_ternary|title=PHP: rfc:isset_ternary|website=php.net|access-date=16 December 2014}}</ref> [[Unicode]] code point [[String literal#Escape sequences|escape syntax]],<ref>{{cite web|url=https://wiki.php.net/rfc/unicode_escape|title=RFC: Unicode Codepoint Escape Syntax|date=2014-11-24|access-date=2014-12-19}}</ref> return type declarations,<ref name="return-types" /> scalar type (integer, float, string and boolean) declarations,<ref name="scalar-types" /> <code><=></code> "spaceship" [[three-way comparison]] operator,<ref>{{cite web|url=https://wiki.php.net/rfc/combined-comparison-operator|title=Combined Comparison (Spaceship) Operator|website=php.net|access-date=2015-05-21}}</ref> [[Generator (computer programming)|generator]] delegation,<ref>{{cite web|url=https://wiki.php.net/rfc/generator-delegation|title=PHP RFC: Generator Delegation|access-date=2015-05-21|website=php.net}}</ref> [[anonymous class]]es,<ref>{{cite web|url=https://wiki.php.net/rfc/anonymous_classes|title=PHP RFC: Anonymous Classes|access-date=2015-05-21|website=php.net}}</ref> simpler and more consistently available [[CSPRNG]] API,<ref>{{cite web|url=https://wiki.php.net/rfc/easy_userland_csprng|title=PHP RFC: Easy User-land CSPRNG|access-date=2015-05-21|website=php.net}}</ref> replacement of many remaining internal PHP "errors" with the more modern [[Exception (computer science)|exceptions]],<ref name="engine_exceptions">{{cite web|url=https://wiki.php.net/rfc/engine_exceptions_for_php7|title=PHP RFC: Exceptions in the engine (for PHP 7)|access-date=2015-05-21|website=php.net}}</ref> and shorthand syntax for importing multiple items from a namespace.<ref>{{cite web|url=https://wiki.php.net/rfc/group_use_declarations|title=PHP RFC: Group Use Declarations|access-date=2015-05-21|website=php.net}}</ref>
|-
| {{Version |o | 7.1}}
| 1 December 2016
| 1 December 2019<ref name="supportedversions"/>
| {{code|lang=php|iterable}} type,<ref>{{cite web|url=https://wiki.php.net/rfc/iterable|title=PHP: rfc:iterable|website=php.net|date=2016-06-10|access-date=2023-06-30}}</ref> nullable types,<ref>{{cite web|url=https://wiki.php.net/rfc/nullable_types|title=PHP: rfc:nullable_types|website=php.net|date=2014-04-10|access-date=2023-06-30}}</ref> [[Void type|{{code|lang=php|void}} return type]],<ref>{{cite web|url=http://wiki.php.net/rfc/void_return_type|title=PHP: rfc:void_return_type|website=php.net|date=2015-11-09|access-date=2015-11-14}}</ref> class constant [[information hiding|visibility modifiers]],<ref>{{cite web|url=https://wiki.php.net/rfc/class_const_visibility|title=PHP: rfc:class_constant_visibility|website=php.net|date=2015-10-27|access-date=2015-12-08}}</ref> short list syntax,<ref>{{cite web|url=https://wiki.php.net/rfc/short_list_syntax|title=PHP: rfc:short_list_syntax|website=php.net|date=2016-04-07|access-date=2023-06-30}}</ref> multi-catch<ref>{{cite web|url=https://wiki.php.net/rfc/multiple-catch|title=PHP: rfc:multiple-catch|website=php.net|date=2016-03-06|access-date=2023-06-30}}</ref>
|-
| {{Version |o | 7.2}}
| 30 November 2017
| 30 November 2020<ref name="supportedversions"/>
| Object parameter and return type declaration,<ref>{{cite web|url=https://wiki.php.net/rfc/object-typehint|title=PHP: rfc:object-typehint|website=wiki.php.net}}</ref> libsodium extension,<ref>{{cite web|url=https://wiki.php.net/rfc/libsodium|title=PHP: rfc:libsodium|website=wiki.php.net}}</ref> abstract method overriding,<ref>{{cite web|url=https://wiki.php.net/rfc/allow-abstract-function-override|title=PHP: rfc:allow-abstract-function-override|website=wiki.php.net}}</ref> parameter type widening<ref>{{cite web|url=https://wiki.php.net/rfc/parameter-no-type-variance|title=PHP: rfc:parameter-no-type-variance|website=wiki.php.net}}</ref>
|-
| {{Version |o | 7.3}}
| 6 December 2018<ref>{{cite web|url=https://wiki.php.net/todo/php73|title=PHP: todo:php73|website=wiki.php.net}}</ref>
| 6 December 2021
| Flexible [[Here document#PHP|Heredoc]] and Nowdoc syntax,<ref>{{cite web|url=https://wiki.php.net/rfc/flexible_heredoc_nowdoc_syntaxes|title=PHP: rfc:flexible_heredoc_nowdoc_syntaxes|website=wiki.php.net}}</ref> support for reference assignment and array deconstruction with {{code|lang=php|code=list()}},<ref>{{cite web|url=https://wiki.php.net/rfc/list_reference_assignment|title=PHP: rfc:list_reference_assignment|website=wiki.php.net}}</ref> PCRE2 support,<ref>{{cite web|url=https://wiki.php.net/rfc/pcre2-migration|title=PHP: rfc:pcre2-migration|website=wiki.php.net}}</ref> {{code|lang=php|code=hrtime}} function<ref>{{cite web|url=https://php.net/manual/en/function.hrtime.php|title=PHP: hrtime{{snd}} Manual|website=php.net}}</ref>
|-
| {{Version |o | 7.4}}
| 28 November 2019<ref>{{Cite web|url=https://www.php.net/archive/2019.php#2019-11-28-1|title=PHP 7.4.0 Released!|website=php.net|access-date=2019-11-28}}</ref>
| 28 November 2022
| Typed properties 2.0,<ref>{{Cite web|url=https://wiki.php.net/rfc/typed_properties_v2|title=PHP: rfc:typed_properties_v2|website=wiki.php.net|access-date=2019-04-04}}</ref> preloading,<ref>{{Cite web|url=https://wiki.php.net/rfc/preload|title=PHP: rfc:preload|website=wiki.php.net|access-date=2019-04-04}}</ref> null-coalescing assignment operator,<ref>{{Cite web|url=https://wiki.php.net/rfc/null_coalesce_equal_operator|title=PHP: rfc:null_coalesce_equal_operator|website=wiki.php.net|access-date=2019-04-04}}</ref> improve {{code|lang=php|code=openssl_random_pseudo_bytes}},<ref>{{Cite web|url=https://wiki.php.net/rfc/improve-openssl-random-pseudo-bytes|title=PHP: rfc:improve-openssl-random-pseudo-bytes|website=wiki.php.net|access-date=2019-04-04}}</ref> weak references,<ref name="php-8-weak-refs">{{Cite web|url=https://wiki.php.net/rfc/weakrefs|title=PHP: rfc:weakrefs|website=wiki.php.net|access-date=2019-04-05}}</ref> [[Foreign function interface|foreign function interface (FFI)]],<ref>{{Cite web|url=https://wiki.php.net/rfc/ffi|title=PHP: rfc:ffi|website=wiki.php.net|access-date=2019-04-05}}</ref> always available hash extension,<ref>{{Cite web|url=https://wiki.php.net/rfc/permanent_hash_ext|title=PHP: rfc:permanent_hash_ext|website=wiki.php.net|access-date=2019-04-05}}</ref> password hash registry,<ref>{{Cite web|url=https://wiki.php.net/rfc/password_registry|title=PHP: rfc:password_registry|website=wiki.php.net|access-date=2019-04-05}}</ref> multibyte string splitting,<ref>{{Cite web|url=https://wiki.php.net/rfc/mb_str_split|title=PHP: rfc:mb_str_split|website=wiki.php.net|access-date=2019-04-05}}</ref> reflection for references,<ref>{{Cite web|url=https://wiki.php.net/rfc/reference_reflection|title=PHP: rfc:reference_reflection|website=wiki.php.net|access-date=2019-04-05}}</ref> unbundle ext/wddx,<ref>{{Cite web|url=https://wiki.php.net/rfc/deprecate-and-remove-ext-wddx|title=PHP: rfc:deprecate-and-remove-ext-wddx|website=wiki.php.net|access-date=2019-04-05}}</ref> new custom object serialization mechanism<ref>{{Cite web|url=https://wiki.php.net/rfc/custom_object_serialization|title=PHP: rfc:custom_object_serialization|website=wiki.php.net|access-date=2019-04-05}}</ref>
|-
| {{Version |o | 8.0}}
| 26 November 2020<ref>{{Cite web|url=https://www.php.net/supported-versions.php|title=PHP: Supported Versions|website=php.net|access-date=2023-11-26}}</ref>
| 26 November 2023
| [[just-in-time compilation|Just-In-Time (JIT) compilation]],<ref name="php-8-JIT">{{Cite web|url=https://wiki.php.net/rfc/jit|title=PHP: rfc:jit|website=wiki.php.net|access-date=2019-04-05}}</ref> arrays starting with a negative index,<ref>{{Cite web|url=https://wiki.php.net/rfc/negative_array_index|title=PHP: rfc:negative_array_index|website=wiki.php.net|access-date=2019-04-05}}</ref> stricter/saner language semantics (validation for abstract trait methods),<ref>{{cite web |title=PHP RFC: Validation for abstract trait methods |url=https://wiki.php.net/rfc/abstract_trait_method_validation |website=wiki.php.net |access-date=14 August 2020}}</ref> saner string to number comparisons,<ref>{{cite web |title=PHP RFC: Saner string to number comparisons |url=https://wiki.php.net/rfc/string_to_number_comparison |website=wiki.php.net |access-date=14 August 2020}}</ref> saner numeric strings,<ref>{{cite web |title=PHP RFC: Saner numeric strings |url=https://wiki.php.net/rfc/saner-numeric-strings |website=wiki.php.net |access-date=14 August 2020}}</ref> {{code|lang=php|TypeError}} on invalid arithmetic/bitwise operators,<ref>{{cite web |title=PHP RFC: Stricter type checks for arithmetic/bitwise operators |url=https://wiki.php.net/rfc/arithmetic_operator_type_checks |website=wiki.php.net |access-date=14 August 2020}}</ref> reclassification of various engine errors,<ref>{{cite web |title=PHP RFC: Reclassifying engine warnings |url=https://wiki.php.net/rfc/engine_warnings |website=wiki.php.net |access-date=14 August 2020}}</ref> consistent type errors for internal functions,<ref>{{Cite web|url=https://wiki.php.net/rfc/consistent_type_errors|title=PHP: rfc:consistent_type_errors|website=wiki.php.net|access-date=2019-04-05}}</ref> fatal error for incompatible method signatures<ref>{{Cite web|url=https://wiki.php.net/rfc/lsp_errors|title=PHP: rfc:lsp_errors|website=wiki.php.net|access-date=2019-05-26}}</ref>), locale-independent float to string conversion,<ref>{{cite web |title=PHP RFC: Locale-independent float to string cast |url=https://wiki.php.net/rfc/locale_independent_float_to_string |website=wiki.php.net |access-date=14 August 2020}}</ref> variable syntax tweaks,<ref>{{cite web |title=PHP RFC: Variable Syntax Tweaks |url=https://wiki.php.net/rfc/variable_syntax_tweaks|website=wiki.php.net |access-date=14 August 2020}}</ref> attributes,<ref>{{cite web |title=PHP RFC: Attributes V2 |url=https://wiki.php.net/rfc/attributes_v2 |website=wiki.php.net |access-date=14 August 2020}}</ref><ref>{{Cite web|title=PHP RFC: Attribute Amendments|url=https://wiki.php.net/rfc/attribute_amendments |website=wiki.php.net |access-date=14 August 2020}}</ref><ref>{{Cite web|title=PHP RFC: Shorter Attribute Syntax|url=https://wiki.php.net/rfc/shorter_attribute_syntax|access-date=2020-06-20|website=wiki.php.net}}</ref><ref>{{cite web |title=PHP RFC: Shorter Attribute Syntax Change |url=https://wiki.php.net/rfc/shorter_attribute_syntax_change |website=wiki.php.net |access-date=14 August 2020}}</ref> named arguments,<ref>{{cite web |title=PHP RFC: Named Arguments |url=https://wiki.php.net/rfc/named_params |website=wiki.php.net |access-date=14 August 2020}}</ref> match expression,<ref>{{cite web |title=PHP RFC: Match expression v2 |url=https://wiki.php.net/rfc/match_expression_v2 |website=wiki.php.net |access-date=14 August 2020}}</ref> constructor property promotion,<ref>{{cite web |title=PHP RFC: Constructor Property Promotion |url=https://wiki.php.net/rfc/constructor_promotion |website=wiki.php.net |access-date=14 August 2020}}</ref> union types,<ref>{{cite web |title=PHP RFC: Union Types 2.0 |url=https://wiki.php.net/rfc/union_types_v2 |website=wiki.php.net |access-date=14 August 2020}}</ref> {{code|lang=php|mixed}} type,<ref>{{cite web |title=PHP RFC: Mixed Type v2 |url=https://wiki.php.net/rfc/mixed_type_v2 |website=wiki.php.net |access-date=14 August 2020}}</ref> static return type,<ref>{{cite web |title=PHP RFC: Static return type |url=https://wiki.php.net/rfc/static_return_type |website=wiki.php.net |access-date=14 August 2020}}</ref> nullsafe operator,<ref name="nullsafe-operator-rfc">{{cite web |title=PHP RFC: Nullsafe operator |url=https://wiki.php.net/rfc/nullsafe_operator |website=wiki.php.net |access-date=14 August 2020}}</ref> non-capturing catches,<ref>{{cite web |title=PHP RFC: non-capturing catches |url=https://wiki.php.net/rfc/non-capturing_catches |website=wiki.php.net |access-date=14 August 2020}}</ref> {{code|lang=php|throw}} expression,<ref name="throw-expression-php8">{{cite web |title=PHP RFC: throw expression |url=https://wiki.php.net/rfc/throw_expression |website=wiki.php.net |access-date=14 August 2020}}</ref> JSON extension is always available.<ref name="ext-json-always-available">{{cite web |last1=Andre |first1=Tyson |title=PHP RFC: Always available JSON extension |url=https://wiki.php.net/rfc/always_enable_json |website=PHP |access-date=25 October 2020}}</ref>
|-
| {{Version |co | 8.1}}
| 25 November 2021<ref>{{Cite web |title=PHP: todo:php81 |url=https://wiki.php.net/todo/php81 |access-date=2022-06-16 |website=wiki.php.net}}</ref>
| 25 November 2024
| Explicit octal integer literal notation,<ref>{{Cite web|url=https://wiki.php.net/rfc/explicit_octal_notation|title=PHP RFC: Explicit octal integer literal notation|website=wiki.php.net|access-date=2020-11-25}}</ref> enumerations,<ref>{{Cite web|url=https://wiki.php.net/rfc/enumerations|title=PHP RFC: Enumerations|website=wiki.php.net|access-date=2021-03-25}}</ref> read-only properties,<ref>{{Cite web|title=PHP: rfc:readonly_properties_v2|url=https://wiki.php.net/rfc/readonly_properties_v2|access-date=2021-11-26|website=wiki.php.net}}</ref> first-class callable syntax,<ref>{{Cite web|title=PHP: rfc:first_class_callable_syntax|url=https://wiki.php.net/rfc/first_class_callable_syntax|access-date=2021-11-26|website=wiki.php.net}}</ref> {{code|lang=php|new}} in initializers,<ref>{{Cite web|title=PHP: rfc:new_in_initializers|url=https://wiki.php.net/rfc/new_in_initializers|access-date=2021-11-26|website=wiki.php.net}}</ref> pure intersection types,<ref>{{Cite web|title=PHP: rfc:pure-intersection-types|url=https://wiki.php.net/rfc/pure-intersection-types|access-date=2021-11-26|website=wiki.php.net}}</ref> {{code|lang=php|never}} return type,<ref>{{Cite web|title=PHP: rfc:noreturn_type|url=https://wiki.php.net/rfc/noreturn_type|access-date=2021-11-26|website=wiki.php.net}}</ref> {{code|lang=php|final}} class constraints,<ref>{{Cite web|title=PHP: rfc:final_class_const|url=https://wiki.php.net/rfc/final_class_const|access-date=2021-11-26|website=wiki.php.net}}</ref> fibers<ref>{{Cite web|title=PHP: rfc:fibers|url=https://wiki.php.net/rfc/fibers|access-date=2021-11-26|website=wiki.php.net}}</ref>
|-
| {{Version |co |8.2}}
| 8 December 2022<ref>{{Cite web |title=PHP: todo:php82 |url=https://wiki.php.net/todo/php82 |access-date=2022-06-16 |website=wiki.php.net}}</ref>
| 8 December 2025
| Readonly classes,<ref>{{Cite web |title=PHP: rfc:readonly_classes |url=https://wiki.php.net/rfc/readonly_classes |access-date=2022-06-16 |website=wiki.php.net}}</ref> {{code|lang=php|code=null}}, {{code|lang=php|code=false}}, and {{code|lang=php|code=true}} as stand-alone types,<ref>{{Cite web |title=PHP: rfc:null-false-standalone-types |url=https://wiki.php.net/rfc/null-false-standalone-types |access-date=2022-06-16 |website=wiki.php.net}}</ref><ref>{{Cite web |title=PHP: rfc:true-type |url=https://wiki.php.net/rfc/true-type |access-date=2022-06-16 |website=wiki.php.net}}</ref> locale-independent case conversion,<ref>{{Cite web |title=PHP: rfc:strtolower-ascii |url=https://wiki.php.net/rfc/strtolower-ascii |access-date=2022-06-16 |website=wiki.php.net}}</ref> disjunctive normal form types,<ref>{{Cite web |title=PHP: rfc:dnf_types |url=https://wiki.php.net/rfc/dnf_types |access-date=2023-02-07 |website=wiki.php.net}}</ref> constants in traits<ref>{{Cite web |title=PHP: rfc:constants_in_traits |url=https://wiki.php.net/rfc/constants_in_traits |access-date=2023-02-07 |website=wiki.php.net}}</ref>
|-
| {{Version |c | 8.3}}
| 23 November 2023<ref>{{Cite web |date=23 November 2023 |title=PHP 8.3.0 Released! |url=https://www.php.net/archive/2023.php#2023-11-23-2 |access-date=24 November 2023 |website=php.net}}</ref>
| 23 November 2026
| Typed class constants,<ref>{{Cite web |title=PHP: rfc:typed_class_constants |url=https://wiki.php.net/rfc/typed_class_constants |access-date=2023-12-17 |website=wiki.php.net}}</ref> dynamic class constant fetch,<ref>{{Cite web |title=PHP: rfc:dynamic_class_constant_fetch |url=https://wiki.php.net/rfc/dynamic_class_constant_fetch |access-date=2023-12-17 |website=wiki.php.net}}</ref> {{code|lang=php|code=#[\Override]}} attribute,<ref>{{Cite web |title=PHP: rfc:marking_overriden_methods |url=https://wiki.php.net/rfc/marking_overriden_methods |access-date=2023-12-17 |website=wiki.php.net}}</ref> deep-cloning of read-only properties,<ref>{{Cite web |title=PHP: rfc:readonly_amendments |url=https://wiki.php.net/rfc/readonly_amendments |access-date=2023-12-17 |website=wiki.php.net}}</ref> new {{code|lang=php|code=json_validate}} function,<ref>{{Cite web |title=PHP: rfc:json_validate |url=https://wiki.php.net/rfc/json_validate |access-date=2023-12-17 |website=wiki.php.net}}</ref> randomizer additions,<ref>{{Cite web |title=PHP: rfc:randomizer_additions |url=https://wiki.php.net/rfc/randomizer_additions |access-date=2023-12-17 |website=wiki.php.net}}</ref> the command-line linter supports multiple files
|-
| {{Version |p | 8.4}}
| 21 November 2024<ref>{{Cite web |date=26 March 2024 |title=PHP: todo: php84|url=https://wiki.php.net/todo/php84 |access-date=26 March 2024 |website=php.net}}</ref>
| 21 November 2027
|
|- class="sortbottom"
| colspan="4" | {{Version |l |show=111101}}
|}
Beginning on 28 June 2011, the PHP Development Team implemented a timeline for the release of new versions of PHP.<ref name="releaseprocess">{{cite web|title=PHP: Release Process|url=https://wiki.php.net/rfc/releaseprocess|access-date=2013-10-06|date=2011-06-20}}</ref> Under this system, at least one release should occur every month. Once per year, a minor release should occur which may include new features. Every minor release should at least be supported for two years with security and bug fixes, followed by at least one year of only security fixes, for a total of a three-year release process for every minor release. No new features, unless small and self-contained, are to be introduced into a minor release during the three-year release process.
== <span id=ELEPHPANT>Mascot</span> ==
[[File:Webysther 20160423 - Elephpant.svg|thumb|200px|The elePHPant, PHP mascot]]
The mascot of the PHP project is the ''elePHPant'', a blue [[elephant]] with the PHP logo on its side, designed by Vincent Pontier<ref>{{cite web|title=PHP: ElePHPant|url=https://php.net/elephpant.php|date=4 Oct 2014|access-date=4 Oct 2014}}</ref> in 1998.<ref>{{cite web|url=https://wwphp-fb.github.io/faq/community/elephpant/|title=Redirecting…|website=wwphp-fb.github.io}}</ref> "The (PHP) letters were forming the shape of an elephant if viewed in a sideways angle."<ref>{{cite web|url=https://7php.com/elephpant/|title=The PHP Mascot's Birth - Creator Of The elePHPant Vincent Pontier Reveals The True Story!|website=7php.com|date=2014-01-06}}</ref> The elePHPant is sometimes differently coloured when in [[plush toy]] form.<ref>{{Cite web |title=ElePHPant |url=https://docs.php.earth/php/community/elephpant/ |access-date=2024-02-13 |website=PHP.earth |language=en}}</ref>
Many variations of this mascot have been made over the years. Only the elePHPants based on the original design by Vincent Pontier are considered official by the community.<ref>{{Cite web|url=https://www.php.net/elephpant.php|title=PHP: ElePHPant|website=www.php.net}}</ref> These are collectable and some of them are extremely rare.<ref>{{Cite web|url=https://afieldguidetoelephpants.net/|title=A Field Guide to Elephpants|website=afieldguidetoelephpants.net}}</ref>
== Syntax ==
{{Main|PHP syntax and semantics}}
[[File:"Hello World" Application in PHP.png|thumb|A "Hello World" application in PHP 7.4 running on its built-in development server]]
The following [["Hello, World!" program]] is written in PHP code embedded in an [[HTML]] document:
<syntaxhighlight lang="html+php" highlight="7-9">
<!DOCTYPE html>
<html>
<head>
<title>PHP "Hello, World!" program</title>
</head>
<body>
<p><?= 'Hello, World!' ?></p>
</body>
</html>
</syntaxhighlight>
However, as no requirement exists for PHP code to be embedded in HTML, the simplest version of ''Hello, World!'' may be written like this, with the closing tag <syntaxhighlight lang="PHP" inline="">?></syntaxhighlight> omitted as preferred in files containing pure PHP code.<ref>{{cite web|url=https://www.php.net/manual/en/language.basic-syntax.phptags.php |title=tags{{snd}} Manual |website=php.net |access-date=2014-02-17}}</ref>
<syntaxhighlight lang="php5">
<?php echo 'Hello, World!';
</syntaxhighlight>
The PHP interpreter only executes PHP code within its [[delimiter]]s. Anything outside of its delimiters is not processed by PHP, although the non-PHP text is still subject to [[control structure]]s described in PHP code. The most common delimiters are <syntaxhighlight lang="PHP" inline=""><?php</syntaxhighlight> to open and <syntaxhighlight lang="PHP" inline="">?></syntaxhighlight> to close PHP sections. The shortened form <syntaxhighlight lang="PHP" inline=""><?</syntaxhighlight> also exists. This short delimiter makes script files less portable since support for them can be disabled in the local PHP configuration and it is therefore discouraged.<ref name="rfc-shortags" /><ref name="basic syntax">{{cite web|title=PHP: Basic syntax|url=https://www.php.net/manual/en/language.basic-syntax.php|publisher=The PHP Group|access-date=2008-02-22}}</ref> Conversely, there is no recommendation against the echo short tag <syntaxhighlight lang="PHP" inline=""><?=</syntaxhighlight>.<ref>{{cite web|access-date=2016-01-03|url=https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md|title=Basic Coding Standard|publisher=PHP Framework Interoperability Group}}</ref> Prior to PHP 5.4.0, this short syntax for <syntaxhighlight lang="php" inline="">echo</syntaxhighlight> only works with the <code>short_open_tag</code> configuration setting enabled, while for PHP 5.4.0 and later it is always available.<ref>{{cite web|url=https://www.php.net/echo |title=echo{{snd}} Manual |website=php.net |access-date=2014-02-17}}</ref><ref>{{cite web|url=https://www.php.net/manual/en/ini.core.php#ini.short-open-tag |title=Description of core php.ini directives{{snd}} Manual |website=php.net |date=2002-03-17 |access-date=2014-02-17}}</ref><ref name="rfc-shortags">{{cite web |url=http://wiki.php.net/rfc/shortags |title=PHP: rfc:shortags |website=php.net |date=2008-04-03 |access-date=2014-05-08 }}</ref> The purpose of all these delimiters is to separate PHP code from non-PHP content, such as [[JavaScript]] code or HTML markup.<ref>{{cite web|access-date=2008-02-25|url=https://www.php.net/manual/en/tutorial.firstpage.php|title=Your first PHP-enabled page |publisher=The PHP Group}}</ref> So the shortest [["Hello, World!" program]] written in PHP is:
<syntaxhighlight lang="html+php">
<?='Hello, World!';
</syntaxhighlight>
The first form of delimiters, <syntaxhighlight lang="PHP" inline><?php</syntaxhighlight> and <syntaxhighlight lang="PHP" inline>?></syntaxhighlight>, in [[XHTML]] and other [[XML]] documents, creates correctly formed XML processing instructions.<ref>{{cite web | url = http://www.w3.org/TR/2008/REC-xml-20081126/#sec-pi | title = Processing Instructions | work = Extensible Markup Language (XML) 1.0 (Fifth Edition) | publisher = W3C | date = 26 November 2008 | last = Bray | first = Tim | access-date = 2009-06-18|display-authors=etal}}</ref> This means that the resulting mixture of PHP code and other markups in the server-side file is itself well-formed XML.
{{Anchor|TYPE-HINTING}}
Variables are [[Sigil (computer programming)|prefixed]] with a [[dollar sign|dollar symbol]], and a [[primitive type|type]] does not need to be specified in advance. PHP 5 introduced ''type declarations'' that allow functions to force their parameters to be objects of a specific class, arrays, interfaces or [[callback function]]s. However, before PHP 7, type declarations could not be used with scalar types such as integers or strings.<ref name="scalar-types" />
Below is an example of how PHP variables are declared and initialized.
<syntaxhighlight lang="php">
<?php
$name = 'John'; // variable of string type being declared and initialized
$age = 18; // variable of integer type being declared and initialized
$height = 5.3; // variable of double type being declared and initialized
echo $name . ' is ' . $height . "m tall\n"; // concatenating variables and strings
echo "$name is $age years old."; // interpolating variables to string
?>
</syntaxhighlight>
Unlike function and class names, variable names are case-sensitive. Both double-quoted ("") and [[heredoc]] strings provide the ability to interpolate a variable's value into the string.<ref>{{cite web|access-date=2008-03-16|url=https://www.php.net/manual/en/language.variables.php|title=Variables |publisher=The PHP Group}}</ref> PHP treats [[newline]]s as [[whitespace character|whitespace]] in the manner of a [[free-form language]], and statements are terminated by a semicolon.<ref>{{cite web|access-date=2008-03-16|url=https://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]]: <syntaxhighlight lang="PHP" inline>/* */</syntaxhighlight> marks block and inline comments; <syntaxhighlight lang="PHP" inline>//</syntaxhighlight> or <syntaxhighlight lang="PHP" inline>#</syntaxhighlight> are used for one-line comments.<ref>{{cite web|access-date=2008-03-16|url=https://www.php.net/manual/en/language.basic-syntax.comments.php|title=Comments |publisher=The PHP Group}}</ref> The <code>echo</code> statement is one of several facilities PHP provides to output text.{{Citation needed|date=November 2023}}
In terms of keywords and language syntax, PHP is similar to C-style syntax. <syntaxhighlight lang="PHP" inline>if</syntaxhighlight> conditions, <syntaxhighlight lang="PHP" inline>for</syntaxhighlight> and <syntaxhighlight lang="PHP" inline>while</syntaxhighlight> loops and function returns are similar in syntax to languages such as C, C++, C#, Java and Perl.{{Citation needed|date=November 2023}}
=== Data types ===
PHP is [[strong and weak typing|loosely typed]]. It stores integers in a platform-dependent range, either as a 32, 64 or 128-bit [[signed number representations|signed]] [[integer (computer science)|integer]] equivalent to the [[C variable types and declarations|C-language long type]]. Unsigned integers are converted to signed values in certain situations, which is different behaviour to many 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 = March 27, 2007 | publisher = MySQL Performance Blog | access-date = 2007-03-28}}</ref> Integer variables can be assigned using decimal (positive and negative), [[octal]], [[hexadecimal]], and [[binary code|binary]] notations.{{Citation needed|date=November 2023}}
[[Floating-point number]]s 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|access-date=2008-03-16|url=https://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; <code>NULL</code> is the only allowed value for this data type.<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, nowdoc or [[heredoc]] syntax.<ref>{{cite web|access-date=2008-03-21|url=https://www.php.net/manual/en/language.types.string.php|title=Strings |publisher=The PHP Group}}</ref>
The '''Standard PHP Library''' (SPL) attempts to solve standard problems and implements efficient data access interfaces and classes.<ref>{{cite web | url = https://www.php.net/spl | title = SPL – StandardPHPLibrary | date = March 16, 2009 | website = PHP.net | access-date = 2009-03-16}}</ref>
=== Functions ===
PHP defines a large array of functions in the core language and many are also available in various extensions; these functions are well documented online [https://www.php.net/docs.php PHP documentation].<ref name="functions" /> However, the built-in library has a wide variety of naming conventions and associated inconsistencies, as described under [[#History|history]] above.
Custom functions may be defined by the developer:
<syntaxhighlight lang="php">
function myAge(int $birthYear): string
{
// calculate the age by subtracting the birth year from the current year.
$yearsOld = date('Y') - $birthYear;
// return the age in a descriptive string.
return $yearsOld . ($yearsOld == 1 ? ' year' : ' years');
}
echo 'I am currently ' . myAge(1995) . ' old.';
</syntaxhighlight>
As of {{CURRENTYEAR}}, the output of the above sample program is "I am currently {{#expr: {{CURRENTYEAR}} - 1995}} years old."
In lieu of [[function pointer]]s, functions in PHP can be referenced by a string containing their name. In this manner, normal PHP functions can be used, for example, as [[Callback function|callbacks]] or within [[function table]]s.<ref name="variable-functions" /> User-defined functions may be created at any time without being [[Function prototype|prototyped]].<ref name="functions">{{cite web
| url = https://www.php.net/manual/en/functions.user-defined.php
| title = User-defined functions (PHP manual)
| date = 2014-07-04 | access-date = 2014-07-07
| website = php.net
}}</ref><ref name="variable-functions">{{cite web
| url = https://www.php.net/manual/en/functions.variable-functions.php
| title = Variable functions (PHP manual)
| date = 2014-07-04 | access-date = 2014-07-07
| website = php.net
}}</ref> Functions may be defined inside code blocks, permitting a [[dynamic dispatch|run-time decision]] as to whether or not a function should be defined. There is a <code>function_exists</code> function that determines whether a function with a given name has already been defined. Function calls must use parentheses, with the exception of zero-argument class [[constructor (computer science)|constructor]] functions called with the PHP operator <code>new</code>, in which case parentheses are optional.{{Citation needed|date=November 2023}}
Since PHP 4.0.1 <code>create_function()</code>, a thin wrapper around <code>eval()</code>, allowed normal PHP functions to be created during program execution; it was deprecated in PHP 7.2 and removed in PHP 8.0<ref>{{cite web
| url = https://www.php.net/manual/en/function.create-function.php
| title = create_function() (PHP manual)
| date = 2022-04-06 | access-date = 2022-05-04
| website = php.net
}}</ref> in favor of syntax for [[anonymous function]]s or "[[Closure (computer programming)|closure]]s"<ref>{{cite web
| url = https://www.php.net/manual/en/functions.anonymous.php
| title = Anonymous functions (PHP manual)
| date = 2014-07-04 | access-date = 2014-07-07
| website = php.net
}}</ref> that can capture variables from the surrounding scope, which was added in PHP 5.3. Shorthand arrow syntax was added in PHP 7.4:<ref>{{cite web
| url = https://www.php.net/manual/en/functions.arrow.php
| title = Arrow Functions (PHP manual)
| access-date = 2021-01-25
| website = php.net
}}</ref>
<syntaxhighlight lang="php">
function getAdder($x) {
return fn($y) => $x + $y;
}
$adder = getAdder(8);
echo $adder(2); // prints "10"
</syntaxhighlight>
In the example above, <code>getAdder()</code> function creates a closure using passed argument {{code|lang=php|code=$x}}, which takes an additional argument {{code|lang=php|code=$y}}, and returns the created closure to the caller. Such a function is a first-class object, meaning that it can be stored in a variable, passed as a [[parameter (computer programming)|parameter]] to other functions, etc.<ref>{{cite web
| url = http://wiki.php.net/rfc/closures
| title = Request for Comments: Lambda functions and closures
| date = 2008-07-01 | access-date = 2014-07-07
| author1 = Christian Seiler | author2 = Dmitry Stogov
| website = php.net
}}</ref>
Unusually for a dynamically typed language, PHP supports type declarations on function parameters, which are enforced at runtime. This has been supported for classes and interfaces since PHP 5.0, for arrays since PHP 5.1, for "callables" since PHP 5.4, and scalar (integer, float, string and boolean) types since PHP 7.0.<ref name="scalar-types" /> PHP 7.0 also has type declarations for function return types, expressed by placing the type name after the list of parameters, preceded by a colon.<ref name="return-types" /> For example, the <code>getAdder</code> function from the earlier example could be annotated with types like so in PHP 7:
<syntaxhighlight lang="php">
function getAdder(int $x): Closure
{
return fn(int $y): int => $x + $y;
}
$adder = getAdder(8);
echo $adder(2); // prints "10"
echo $adder(null); // throws an exception because an incorrect type was passed
$adder = getAdder([]); // would also throw an exception
</syntaxhighlight>
By default, scalar type declarations follow weak typing principles. So, for example, if a parameter's type is <code>int</code>, PHP would allow not only integers, but also convertible numeric strings, floats or booleans to be passed to that function, and would convert them.<ref name="scalar-types" /> However, PHP 7 has a "strict typing" mode which, when used, disallows such conversions for function calls and returns within a file.<ref name="scalar-types" />
=== PHP objects ===
Basic [[object-oriented programming]] functionality was added in PHP 3 and improved in PHP 4.<ref name="about PHP" /> This allowed for PHP to gain further abstraction, making creative tasks easier for programmers using the language. 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 [[value type]]s.<ref name="php 5 objects">{{cite web|access-date=2008-03-16|url=http://mjtsai.com/blog/2004/07/15/php-5-object-references/|title=PHP 5 Object References |website=mjtsai.com}}</ref> The drawback of this method was that code had to make heavy use of PHP's "reference" variables if it wanted to modify an object it was passed rather than creating a copy of it. In the new approach, objects are referenced by [[handle (computing)|handle]], and not by value.{{Citation needed|date=November 2023}}
PHP 5 introduced private and protected [[member variable]]s and methods, along with [[Abstract type|abstract classes]], [[Final type|final classes]], [[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 [[Interface (computing)|interfaces]] and allowed for multiple interfaces to be implemented. There are special interfaces that allow objects to interact with the runtime system. [[object (computer science)|Objects]] implementing ArrayAccess can be used with [[array data type|array]] syntax and objects 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|access-date=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 <code>clone</code>, the Zend engine will check whether a <code>__clone()</code> method has been defined. If not, it will call a default <code>__clone()</code> which will copy the object's properties. If a <code>__clone()</code> 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 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|access-date=2008-03-16|url=https://www.php.net/language.oop5.cloning|title=Object cloning |publisher=The PHP Group}}</ref>
The [[Visibility (computer science)|visibility]] of PHP properties and methods is defined using the [[Keyword (computer programming)|keywords]] <code>public</code>, <code>private</code>, and <code>protected</code>. The default is public, if only [[variable (programming)|var]] is used; <code>var</code> is a synonym for <code>public</code>. Items declared <code>public</code> can be accessed everywhere. <code>protected</code> limits access to [[inherited class]]es (and to the class that defines the item). <code>private</code> limits visibility only to the class that defines the item.<ref>{{cite web |url=http://theserverpages.com/php/manual/en/language.oop5.visibility.php |title=Visibility (PHP Manual) |website=theserverpages.com |date=2005-05-19 |access-date=2010-08-26 |archive-date=2010-09-24 |archive-url=https://web.archive.org/web/20100924033414/http://theserverpages.com/php/manual/en/language.oop5.visibility.php |url-status=dead }}</ref> Objects of the same type have access to each other's private and protected members even though they are not the same instance.{{Citation needed|date=November 2023}}
==== Example ====
The following is a basic example of [[object-oriented programming]] in PHP 8:
<syntaxhighlight lang="php" line>
<?php
abstract class User
{
protected string $name;
public function __construct(string $name)
{
// make first letter uppercase and the rest lowercase
$this->name = ucfirst(strtolower($name));
}
public function greet(): string
{
return "Hello, my name is " . $this->name;
}
abstract public function job(): string;
}
class Student extends User
{
public function __construct(string $name, private string $course)
{
parent::__construct($name);
}
public function job(): string
{
return "I learn " . $this->course;
}
}
class Teacher extends User
{
public function __construct(string $name, private array $teachingCourses)
{
parent::__construct($name);
}
public function job(): string
{
return "I teach " . implode(", ", $this->teachingCourses);
}
}
$students = [
new Student("Alice", "Computer Science"),
new Student("Bob", "Computer Science"),
new Student("Charlie", "Business Studies"),
];
$teachers = [
new Teacher("Dan", ["Computer Science", "Information Security"]),
new Teacher("Erin", ["Computer Science", "3D Graphics Programming"]),
new Teacher("Frankie", ["Online Marketing", "Business Studies", "E-commerce"]),
];
foreach ([$students, $teachers] as $users) {
echo $users[0]::class . "s:\n";
array_walk($users, function (User $user) {
echo "{$user->greet()}, {$user->job()}\n";
});
}
</syntaxhighlight>
This program outputs the following:
<pre>
Students:
Hello, my name is Alice, I learn Computer Science
Hello, my name is Bob, I learn Computer Science
Hello, my name is Charlie, I learn Business Studies
Teachers:
Hello, my name is Dan, I teach Computer Science, Information Security
Hello, my name is Erin, I teach Computer Science, 3D Graphics Programming
Hello, my name is Frankie, I teach Online Marketing, Business Studies, E-commerce
</pre>
<!-- Note that there are problems with the script in this section. -->
== Implementations ==
The only complete PHP implementation is the original, known simply as PHP. It is the most widely used and is powered by the [[Zend Engine]]. To disambiguate it from other implementations, it is sometimes unofficially called "Zend PHP". The Zend Engine [[Compiler|compiles]] PHP [[source code]] on-the-fly into an internal format that it can execute, thus it works as an [[Interpreter (computing)|interpreter]].<ref>{{cite web|access-date=2009-11-04|url=http://www.linux-tutorial.info/modules.php?name=Howto&pagename=Unix-and-Internet-Fundamentals-HOWTO/languages.html|title=How do computer languages work?|archive-date=2011-07-16|archive-url=https://web.archive.org/web/20110716214917/http://www.linux-tutorial.info/modules.php?name=Howto&pagename=Unix-and-Internet-Fundamentals-HOWTO/languages.html|url-status=dead}}</ref><ref>{{cite book |title=Beginning PHP and MySQL 5: From Novice to Professional |author=Gilmore, W. Jason |page=[https://archive.org/details/beginningphpmysq0000gilm/page/43 43] |date=2006-01-23 |publisher=Apress |isbn=1590595521 |url=https://archive.org/details/beginningphpmysq0000gilm/page/43 }}</ref> It is also the "reference implementation" of PHP, as PHP has no formal specification, and so the semantics of Zend PHP define the semantics of PHP. Due to the complex and nuanced semantics of PHP, defined by how Zend works, it is difficult for competing implementations to offer complete compatibility.{{Citation needed|date=November 2023}}
PHP's single-request-per-script-execution model, and the fact that the Zend Engine is an interpreter, leads to inefficiency; as a result, various products have been developed to help improve PHP performance. In order to speed up execution time and not have to compile the PHP source code every time the web page is accessed, PHP scripts can also be deployed in the PHP engine's internal format by using an [[opcode]] cache, which works by [[Cache (computing)|caching]] the compiled form of a PHP script (opcodes) in [[Shared memory (interprocess communication)|shared memory]] to avoid the overhead of [[parsing]] and [[compiling]] the code every time the script runs. An opcode cache, [[Zend Opcache]], is built into PHP since version 5.5.<ref>{{cite web
| title = [VOTE] Integrating Zend Optimizer+ into the PHP distribution
| url = http://news.php.net/php.internals/66531
| access-date = 2013-03-08
| website = news.php.net
}}</ref> Another example of a widely used opcode cache is the [[Alternative PHP Cache]] (APC), which is available as a [[PHP Extension Community Library|PECL]] extension.<ref>{{cite web
| url = http://www.php.net/manual/en/book.apc.php
| title = Alternative PHP Cache
| access-date = 2013-09-21
| website = PHP.net
| archive-date = 2013-11-15
| archive-url = https://web.archive.org/web/20131115071936/http://php.net/manual/en/book.apc.php
| url-status = dead
}}</ref>
While Zend PHP is still the most popular implementation, several other implementations have been developed. Some of these are [[compiler]]s or support [[JIT compilation]], and hence offer performance benefits over Zend PHP at the expense of lacking full PHP compatibility.{{Citation needed|date=November 2023}} Alternative implementations include the following:
* [[HHVM]] (HipHop Virtual Machine) – developed at Facebook and available as open source, it converts PHP code into a high-level bytecode (commonly known as an [[intermediate language]]), which is then translated into x86-64 machine code dynamically at runtime by a [[Just-in-time compiler|just-in-time]] (JIT) compiler, resulting in up to 6× performance improvements.<ref>{{cite web|url=http://www.hhvm.com/blog/2813/we-are-the-98-5-and-the-16 |title=We are the 98.5% (and the 16%) « HipHop Virtual Machine |website=hhvm.com |date=December 2013 |access-date=2014-02-23}}</ref> However, since version 7.2 Zend has outperformed HHVM,<ref>{{Cite web|url=https://kinsta.com/blog/php-benchmarks/|title=The Definitive PHP 5.6, 7.0, 7.1, 7.2 & 7.3 Benchmarks (2019)|date=2019-01-14 |access-date=2019-04-19}}</ref> and HHVM 3.24 is the last version to officially support PHP.<ref>{{Cite web|url=https://www.infoworld.com/article/3226489/web-development/forget-php-facebooks-hhvm-engine-switches-to-hack-instead.html|title=Forget PHP! Facebook's HHVM engine switches to Hack instead|last=Krill|first=Paul|date=2017-09-20|website=InfoWorld |access-date=2019-02-06}}</ref>
** [[HipHop for PHP|HipHop]] – developed at Facebook and available as open source, it transforms the PHP scripts into [[C++]] code and then compiles the resulting code, reducing the server load up to 50%. In early 2013, Facebook deprecated it in favour of HHVM due to multiple reasons, including deployment difficulties and lack of support for the whole PHP language, including the <code>create_function()</code> and <code>eval()</code> constructs.<ref>{{cite web|title=Announcement on GitHub removing HPHPc support|website=[[GitHub]]|url=https://github.com/facebook/hiphop-php/commit/fc5b95110ff75110ad55bb97f7c93a8c4eb68e3b|access-date=2013-05-24}}</ref>
* [[Parrot virtual machine|Parrot]] – a virtual machine designed to run dynamic languages efficiently; the cross-translator Pipp transforms the PHP source code into the [[Parrot intermediate representation]], which is then translated into the Parrot's bytecode and executed by the virtual machine.
* [[PeachPie]] – a second-generation compiler to .[[.NET Framework|NET]] [[Common Intermediate Language]] (CIL) bytecode, built on the [[Roslyn (compiler)|Roslyn]] platform; successor of Phalanger, sharing several architectural components
* [[Phalanger (compiler)|Phalanger]] – compiles PHP into .Net Common Intermediate Language bytecode; predecessor of PeachPie
* [[Quercus (software)|Quercus]] – compiles PHP into [[Java bytecode]]
== Licensing ==
{{Main|PHP License}}
PHP is [[free software]] released under the [[PHP License]], which stipulates that:<ref>{{cite web|url=https://www.php.net/license/3_01.txt |title=The PHP License, version 3.01|access-date=2010-05-20}}</ref>
{{blockquote
| Products derived from this software may not be called "PHP", nor may "PHP" appear in their name, without prior written permission from group@php.net. You may indicate that your software works in conjunction with PHP by saying "[[Foo]] for PHP" instead of calling it "PHP Foo" or "phpfoo".
}}
This restriction on the use of "PHP" makes the PHP License incompatible with the [[General Public License]] (GPL), while the Zend License is incompatible due to an advertising clause similar to that of the original [[BSD license]].<ref>{{cite web | title = GPL-Incompatible, Free Software Licenses | url = https://www.gnu.org/licenses/license-list.html#GPLIncompatibleLicenses | work = Various Licenses and Comments about Them | publisher = Free Software Foundation|access-date=2011-01-03}}</ref>
== <span id=PDO><span id=ZEPHIR>Development and community</span></span> ==
PHP includes various [[list of PHP libraries|free and open-source libraries]] in its source distribution or uses them in resulting PHP binary builds. PHP is fundamentally an [[Internet]]-aware system with built-in modules for accessing [[File Transfer Protocol]] (FTP) servers and many database servers, including [[PostgreSQL]], [[MySQL]], [[Microsoft SQL Server]] and [[SQLite]] (which is an embedded database), [[Lightweight Directory Access Protocol|LDAP]] servers, and others. Numerous functions are familiar to C programmers, such as those in the [[stdio.h|stdio]] family, are available in standard PHP builds.<ref>{{cite web|access-date=2015-01-14|url=https://php.net/manual/en/indexes.functions.php|title=PHP: Function and Method listing{{snd}} Manual |publisher=The PHP Group}}</ref>
PHP allows developers to write [[Software extension|extensions]] in [[C (programming language)|C]] to add functionality to the PHP language. PHP extensions can be compiled statically into PHP or loaded dynamically at runtime. Numerous 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]]. Other PHP features made available through extensions include integration with [[Internet Relay Chat]] (IRC), dynamic generation of images and [[Adobe Flash]] content, ''PHP Data Objects'' (PDO) as an abstraction layer used for accessing databases,<ref>{{cite web|url=http://www.php.net/manual/en/intro.pdo.php |title=Introduction{{snd}} Manual |website=php.net |date=2013-06-07 |access-date=2013-06-13}}</ref><ref>{{cite web|url=http://www.onlamp.com/pub/a/php/2004/08/05/dataobjects.html|title=Simplify Business Logic with PHP DataObjects — O'Reilly Media|author=Darryl Patterson|date=5 August 2004|website=ibm.com|access-date=16 December 2014|archive-date=16 December 2014|archive-url=https://web.archive.org/web/20141216140653/http://www.onlamp.com/pub/a/php/2004/08/05/dataobjects.html|url-status=dead}}</ref><ref>{{cite web|url=http://www-128.ibm.com/developerworks/db2/library/techarticle/dm-0612xia/|title=IBM — United States|access-date=16 December 2014}}</ref><ref>{{cite web|url=http://www-128.ibm.com/developerworks/library/os-php-dbmistake/index.html |title=Five common PHP database problems |website=ibm.com |date=2006-08-01 |access-date=2013-06-13}}</ref><ref>{{cite web|url=http://www.redbooks.ibm.com/abstracts/sg247218.html|title=IBM Redbooks — Developing PHP Applications for IBM Data Servers|website=redbooks.ibm.com|access-date=16 December 2014}}</ref><ref>{{cite web|url=http://www.phparch.com/issue.php?mid=65|title=php[architect] Magazine - The Journal for PHP Programmers|website=www.phparch.com}}</ref><ref>{{cite magazine|url=http://www.infoworld.com/article/05/10/19/HNphpshow_1.html|title=PHP catching on at enterprises, vying with Java|last=Krill|first=Paul|date=19 October 2005|magazine=InfoWorld|archive-url=https://web.archive.org/web/20140713004345/http://www.infoworld.com/d/developer-world/php-catching-enterprises-vying-java-708|archive-date=13 July 2014}}</ref> and even [[speech synthesis]]. Some of the language's core functions, such as those dealing with strings and arrays, are also implemented as extensions.<ref>{{cite web|url=http://lxr.php.net/xref/PHP_5_4/ext/standard/|archive-url=https://web.archive.org/web/20120316010914/http://lxr.php.net/xref/PHP_5_4/ext/standard/|url-status=dead|archive-date=16 March 2012|title=Cross Reference: /PHP_5_4/ext/standard/|website=php.net|access-date=16 December 2014}}</ref> The [[PHP Extension Community Library]] (PECL) project is a repository for extensions to the PHP language.<ref>{{cite web|access-date=2008-02-25|url=http://www.devnewz.com/090902b.html|title=Developing Custom PHP Extensions |website=devnewz.com |date=2002-09-09 |archive-url = https://web.archive.org/web/20080218045752/http://www.devnewz.com/090902b.html |archive-date = 2008-02-18}}</ref>
Some other projects, such as ''Zephir'', provide the ability for PHP extensions to be created in a high-level language and compiled into native PHP extensions. Such an approach, instead of writing PHP extensions directly in C, simplifies the development of extensions and reduces the time required for programming and testing.<ref>{{cite web
| url = http://docs.zephir-lang.com/en/latest/motivation.html
| title = Why Zephir?
| date = 2015-10-20 | access-date = 2015-12-14
| website = zephir-lang.com
}}</ref>
By December 2018 the PHP Group consisted of ten people: [[Thies C. Arntzen]], [[Stig Bakken]], [[Shane Caraveo]], [[Andi Gutmans]], [[Rasmus Lerdorf]], [[Sam Ruby]], [[Sascha Schumann]], [[Zeev Suraski]], [[Jim Winstead]], and [[Andrei Zmievski]].<ref>{{cite web|title=PHP Credits|url=https://php.net/credits|access-date=2018-12-16}}</ref>
[[Zend Technologies]] provides a [[Zend Certified Engineer|PHP Certification]] based on PHP 7<ref>{{Cite web|title=Learn PHP Via PHP Training and PHP Certification|url=https://www.zend.com/training/php|access-date=2020-11-16|website=www.zend.com}}</ref> exam (and previously based on PHP 5.5) for programmers to become certified PHP developers.
== The PHP Foundation ==
{{Infobox organization
| formation = {{start date and age|2021|11|22}}
| logo = The PHP Foundation Logo.svg
| founder = [[Automattic]], [[Laravel]], [[Acquia]], [[Zend]], Private Packagist, [[Symfony]], Craft CMS, Tideways, [[PrestaShop]], [[JetBrains]]<ref>{{Cite web |last=Walker |first=James |date=2021-12-13 |title=What the New PHP Foundation Means for PHP's Future |url=https://www.howtogeek.com/devops/what-the-new-php-foundation-means-for-phps-future/ |access-date=2023-11-26 |website=How-To Geek |language=en}}</ref>
| website = https://thephp.foundation
}}
On 26 November 2021, the [[JetBrains]] blog announced the creation of The PHP Foundation, which will sponsor the design and development of PHP.<ref>{{Cite web |title=The New Life of PHP – The PHP Foundation {{!}} The PhpStorm Blog |url=https://blog.jetbrains.com/phpstorm/2021/11/the-php-foundation/ |access-date=2022-06-16 |website=The JetBrains Blog |date=22 November 2021 |language=en-US}}</ref>
{| class="wikitable"
!Year
![[Commit (version control)|Commits]]
![[Code review|Reviews]]
![[Request for Comments|RFCs]]
|-
!2022<ref>{{Cite web |title=The PHP Foundation: Impact and Transparency Report 2022 |url=https://thephp.foundation/blog/2022/11/22/transparency-and-impact-report-2022/ |access-date=2023-11-27 |website=thephp.foundation |language=en}}</ref>
|683
|283
|8
|}
The foundation hires "Core Developers" to work on the PHP language's core repository. Roman Pronskiy, a member of the foundation's board, said that they aim to pay "market salaries" to developers.<ref>{{Cite web |last=Anderson |first=Tim |title=PHP Foundation formed to fund core developers |url=https://www.theregister.com/2021/11/23/php_foundation_formed_to_fund/ |access-date=2023-12-05 |website=www.theregister.com |language=en}}</ref>
The response to the foundation has mostly been positive, with the foundation being praised for better supporting the language and helping to stop the decrease in the language's popularity.<ref>{{Cite web |title=Programming languages: This old favourite is gaining popularity again |url=https://www.zdnet.com/article/programming-languages-this-old-favourite-is-gaining-popularity-again/ |access-date=2023-12-05 |website=ZDNET |language=en}}</ref><ref>{{Cite web |title=PHP 8.1 Released With Enums, Read-Only Properties and Fibers |url=https://www.i-programmer.info/news/98-languages/15050-php-81-released.html |access-date=2023-12-05 |website=www.i-programmer.info}}</ref> However, it has also been criticised for adding breaking changes to minor versions of PHP, such as in PHP 8.2 where initialising members of a class out-with the original class scope would cause depreciation errors,<ref>{{Cite web |title=It's time for the PHP Foundation to #StopBreakingPHP |url=https://trongate.io/news/display/TWN4GR/its-time-for-the-php-foundation-to-stopbreakingphp |access-date=2023-11-27 |website=trongate.io}}</ref> these changes impacted a number of open source projects including [[WordPress]].
<ref>{{Cite web |date=2023-11-16 |title=WordPress 6.4 PHP Compatibility |url=https://make.wordpress.org/hosting/2023/11/16/wordpress-6-4-php-compatibility/ |access-date=2023-11-27 |website=Make WordPress Hosting |language=en-US}}</ref>
== <span id=PHPFPM>Installation and configuration</span> ==
[[File:PHP 7.1 - Example phpinfo() Screen.png|thumb|Example output of the phpinfo() function in PHP 7.1]]
There are two primary ways for adding support for PHP to a web server – as a native web server module, or as a CGI executable. PHP has a direct module interface called [[server application programming interface]] (SAPI), which is supported by many web servers including [[Apache HTTP Server]], [[Internet Information Services|Microsoft IIS]] and [[Oracle iPlanet Web Server|iPlanet Web Server]]. Some other web servers, such as OmniHTTPd, support the [[Internet Server Application Programming Interface]] (ISAPI), which is [[Microsoft]]'s web server module interface. If PHP has no module support for a web server, it can always be used as a [[Common Gateway Interface]] (CGI) or [[FastCGI]] processor; in that case, the web server is configured to use PHP's CGI executable to process all requests to PHP files.<ref name="installation">{{cite web
| url = http://www.php.net/manual/en/install.general.php
| title = General Installation Considerations
| access-date = 2013-09-22
| website = php.net
}}</ref>
PHP-FPM (FastCGI Process Manager) is an alternative FastCGI implementation for PHP, bundled with the official PHP distribution since version 5.3.3.<ref>{{cite web
| url = http://www.php.net/archive/2010.php#id2010-07-22-2
| title = News Archive: PHP 5.3.3 Released!
| date = 2010-07-22
| website = php.net}}</ref> When compared to the older FastCGI implementation, it contains some additional features, mostly useful for heavily loaded web servers.<ref>{{cite web
| url = http://www.php.net/manual/en/install.fpm.php
| title = FastCGI Process Manager (FPM)
| access-date = 2013-09-22
| website = php.net
}}</ref>
When using PHP for command-line scripting, a PHP [[command-line interface]] (CLI) executable is needed. PHP supports a CLI [[server application programming interface]] (SAPI) since PHP 4.3.0.<ref>{{cite web
| url = http://www.php.net/manual/en/features.commandline.introduction.php
| title = Command line usage: Introduction
| access-date = 2013-09-22
| website = php.net
}}</ref> The main focus of this SAPI is developing [[command line interface|shell]] applications using PHP. There are quite a few differences between the CLI SAPI and other SAPIs, although they do share many of the same behaviours.<ref>{{cite web
| url = http://www.php.net/manual/en/features.commandline.differences.php
| title = Command line usage: Differences to other SAPIs
| access-date = 2013-09-22
| website = php.net
}}</ref>
PHP has a direct module interface called SAPI for different web servers;<ref name="php-installation2">{{cite web
|url = https://php.net/manual/en/install.general.php|title = General Installation Considerations|access-date = 2013-09-22|website = php.net}}</ref> in case of PHP 5 and Apache 2.0 on Windows, it is provided in form of a [[Dynamic-link library|DLL]] file called {{Mono|php5apache2.dll}},<ref>{{cite web|url = https://php.net/manual/en/install.windows.apache2.php|title = PHP: Apache 2.x on Microsoft Windows|access-date = 2013-09-22|website = php.net|url-status = dead|archive-url = https://web.archive.org/web/20130926122011/http://php.net/manual/en/install.windows.apache2.php|archive-date = 2013-09-26}}</ref> which is a module that, among other functions, provides an interface between PHP and the web server, implemented in a form that the server understands. This form is what is known as a SAPI.{{Citation needed|date=November 2023}}
There are different kinds of SAPIs for various web server extensions. For example, in addition to those listed above, other SAPIs for the PHP language include the Common Gateway Interface and command-line interface.<ref name="php-installation2" /><ref>{{cite web
|url = http://www.php.net/manual/en/features.commandline.introduction.php|title = Command line usage: Introduction|access-date = 2013-09-22|website = php.net}}</ref>
PHP can also be used for writing desktop [[graphical user interface]] (GUI) applications, by using the [[PHP-GTK]] extension. PHP-GTK is not included in the official PHP distribution,<ref name="installation" /> and as an extension, it can be used only with PHP versions 5.1.0 and newer. The most common way of installing PHP-GTK is by compiling it from the source code.<ref>{{cite web
| url = http://gtk.php.net/manual/en/tutorials.installation.php
| title = Installing PHP-GTK 2
| access-date = 2013-09-22
| website = php.net
}}</ref>
When PHP is installed and used in [[Cloud computing|cloud]] environments, [[software development kit]]s (SDKs) are provided for using cloud-specific features.{{Citation needed|date=November 2023}} For example:
* [[Amazon Web Services]] provides the AWS SDK for PHP<ref>{{cite web|url=http://aws.amazon.com/sdkforphp/ |title=AWS SDK for PHP |website=aws.amazon.com |access-date=2014-03-06}}</ref>
* [[Microsoft Azure]] can be used with the Windows Azure SDK for PHP.<ref>{{cite web |url=http://www.interoperabilitybridges.com/projects/php-sdk-for-windows-azure.aspx |title=Windows Azure SDK for PHP — Interoperability Bridges and Labs Center |website=interoperabilitybridges.com |access-date=2014-03-06 |url-status=dead |archive-url=https://web.archive.org/web/20140320152702/http://www.interoperabilitybridges.com/projects/php-sdk-for-windows-azure.aspx |archive-date=2014-03-20 }}</ref>
Numerous configuration options are supported, affecting both core PHP features and extensions.<ref>{{cite web
| url = http://www.php.net/manual/en/configuration.php
| title = Runtime configuration: Table of contents
| access-date = 2013-09-22
| website = php.net
}}</ref><ref>{{cite web
| url = http://www.php.net/manual/en/ini.list.php
| title = php.ini directives: List of php.ini directives
| access-date = 2013-09-22
| website = php.net
}}</ref> Configuration file <code>php.ini</code> is searched for in different locations, depending on the way PHP is used.<ref>{{cite web
| url = http://www.php.net/manual/en/configuration.file.php
| title = Runtime configuration: The configuration file
| access-date = 2013-09-22
| publisher = PHP.net
}}</ref> The configuration file is split into various sections,<ref>{{cite web
| url = http://www.php.net/manual/en/ini.sections.php
| title = php.ini directives: List of php.ini sections
| access-date = 2013-09-22
| publisher = PHP.net
}}</ref> while some of the configuration options can be also set within the web server configuration.<ref>{{cite web
| url = http://www.php.net/manual/en/configuration.changes.modes.php
| title = Runtime configuration: Where a configuration setting may be set
| access-date = 2013-09-22
| publisher = PHP.net
}}</ref>
== Use ==
[[File:LAMP software bundle.svg|thumb|upright=2|A broad overview of the LAMP software bundle, displayed here together with [[Squid (software)|Squid]] ]]
PHP is a general-purpose scripting language that is especially suited to [[server-side scripting|server-side]] [[web development]], in which case PHP generally runs on a [[web server]]. Any PHP code in a requested file is [[execution (computing)|executed]] by the PHP runtime, usually to create [[dynamic web page]] content or dynamic images used on websites or elsewhere.<ref>{{cite web|url=https://php.net/manual/en/book.image.php |title=PHP Manual Image Processing and GD; |publisher= php.net |access-date=2011-04-09}}</ref> It can also be used for [[command-line]] scripting and [[client-side]] [[graphical user interface]] (GUI) applications. PHP can be deployed on most web servers, many [[operating system]]s and [[computing platform|platforms]], and can be used with many [[relational database management system]]s (RDBMS). Most [[web hosting]] providers support PHP for use by their clients. 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|access-date=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|archive-date=2008-02-19|archive-url=https://web.archive.org/web/20080219180226/http://www.onlamp.com/pub/a/php/2001/05/03/php_foundations.html|url-status=dead}}</ref>
[[File:Scheme dynamic page en.svg|thumb|upright=2|Dynamic web page: example of [[server-side scripting]] (PHP and MySQL)]]
Originally designed to create dynamic [[web page]]s, PHP now focuses mainly on [[server-side scripting]],<ref>{{cite web|url=http://webmaster.iu.edu/PHPlanguage/index.shtml|title=PHP Server-Side Scripting Language|publisher=[[Indiana University]]|access-date=2008-02-25|date=2007-04-04|archive-url=https://web.archive.org/web/20160121223739/http://webmaster.iu.edu/tools-and-guides/programming-languages/php.phtml|archive-date=2016-01-21}}</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 [[Python (programming language)|Python]], [[Microsoft]]'s [[ASP.NET]], [[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|access-date=2008-02-25}}</ref> and <code>[[mod_perl]]</code><!-- do not remove the underscore from mod_perl: it is part of the name -->. PHP has also attracted the development of many [[software framework]]s that provide building blocks and a design structure to promote [[rapid application development]] (RAD).{{Citation needed|date=November 2023}} Some of these include [[PRADO (framework)|PRADO]], [[CakePHP]], [[Symfony]], [[CodeIgniter]], [[Laravel]], [[Yii Framework]], [[Phalcon (framework)|Phalcon]] and [[Laminas]], offering features similar to other [[web framework]]s.
The [[LAMP (software bundle)|LAMP architecture]] has become popular in the web industry as a way of deploying web applications.<ref>{{cite web|url=http://www.ibm.com/developerworks/library/os-5waystunelamp/index.html|title=Five simple ways to tune your LAMP application| website=[[IBM]] |date=2011-01-25}}</ref> 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]], [[Perl]], or some mix of the three. Similar packages, [[WAMP (software bundle)|WAMP]] and [[MAMP]], are also available for [[Microsoft Windows|Windows]] and [[macOS]], with the first letter standing for the respective operating system. Although both PHP and Apache are provided as part of the macOS base install, users of these packages seek a simpler installation mechanism that can be more easily kept up to date.{{Citation needed|date=November 2023}}
For specific and more advanced usage scenarios, PHP offers a well-defined and documented way for writing custom extensions in [[C (programming language)|C]] or [[C++]].<ref>{{cite web
| url = http://www.php.net/manual/en/internals2.structure.php
| title = PHP at the core: Extension structure
| access-date = 2013-09-22
| website = PHP.net
}}</ref><ref>{{cite web
| url = http://www.php.net/manual/en/internals2.counter.php
| title = PHP at the core: The "counter" Extension – A Continuing Example
| access-date = 2013-09-22
| website = PHP.net
}}</ref><ref>{{cite web
| url = http://devzone.zend.com/303/extension-writing-part-i-introduction-to-php-and-zend/
| title = Extension Writing Part I: Introduction to PHP and Zend
| date = 2005-03-01
| access-date = 2013-09-22
| publisher = [[Zend Technologies]]
| archive-url = https://web.archive.org/web/20130924233638/http://devzone.zend.com/303/extension-writing-part-i-introduction-to-php-and-zend/
| archive-date = 2013-09-24
| url-status = dead
}}</ref><ref>{{cite web
| url = http://devzone.zend.com/317/extension-writing-part-ii-parameters-arrays-and-zvals/
| title = Extension Writing Part II: Parameters, Arrays, and ZVALs
| date = 2005-06-06
| access-date = 2013-09-22
| publisher = [[Zend Technologies]]
| archive-url = https://web.archive.org/web/20130926091658/http://devzone.zend.com/317/extension-writing-part-ii-parameters-arrays-and-zvals/
| archive-date = 2013-09-26
| url-status = dead
}}</ref><ref>{{cite web
| url = http://devzone.zend.com/318/extension-writing-part-ii-parameters-arrays-and-zvals-continued/
| title = Extension Writing Part II: Parameters, Arrays, and ZVALs (continued)
| date = 2005-06-06
| access-date = 2013-09-22
| publisher = [[Zend Technologies]]
| archive-url = https://web.archive.org/web/20130926091655/http://devzone.zend.com/318/extension-writing-part-ii-parameters-arrays-and-zvals-continued/
| archive-date = 2013-09-26
| url-status = dead
}}</ref><ref>{{cite web
| url = http://devzone.zend.com/446/extension-writing-part-iii-resources/
| title = Extension Writing Part III: Resources
| date = 2006-05-12
| access-date = 2013-09-22
| publisher = [[Zend Technologies]]
| archive-url = https://web.archive.org/web/20130926091645/http://devzone.zend.com/446/extension-writing-part-iii-resources/
| archive-date = 2013-09-26
| url-status = dead
}}</ref><ref>{{cite web
| url = http://devzone.zend.com/1435/wrapping-c-classes-in-a-php-extension/
| title = Wrapping C++ Classes in a PHP Extension
| date = 2009-04-22
| access-date = 2013-09-22
| publisher = [[Zend Technologies]]
| archive-url = https://web.archive.org/web/20130920011549/http://devzone.zend.com/1435/wrapping-c-classes-in-a-php-extension/
| archive-date = 2013-09-20
| url-status = dead
}}</ref>{{Primary source inline|date=November 2023|reason=Since this is a broad generalization, secondary sources are required}} Besides extending the language itself in form of additional [[Library (computing)|libraries]], extensions are providing a way for improving execution speed where it is critical and there is room for improvements by using a true [[compiled language]].<ref>{{cite web
| url = https://stackoverflow.com/q/1110682
| title = Extending PHP with C++?
| access-date = 2013-09-22
| publisher = [[Stack Overflow]]
}}</ref><ref>{{cite web
| url = https://stackoverflow.com/q/1502244
| title = How can I use C++ code to interact with PHP?
| access-date = 2013-09-22
| publisher = [[Stack Overflow]]
}}</ref> PHP also offers well-defined ways for embedding itself into other software projects. That way PHP can be easily used as an internal [[scripting language]] for another project, also providing tight interfacing with the project's specific internal [[data structure]]s.<ref>{{cite book
| title = Extending and Embedding PHP
| first = Sara | last = Golemon
| year = 2006
| publisher = Sams | isbn = 978-0-672-32704-9
}}</ref>
PHP received mixed reviews due to lacking support for [[Multithreading (software)|multithreading]] at the core language level,<ref>{{cite web
| url = https://bugs.php.net/bug.php?id=46919
| title = Request #46919: Multithreading
| access-date = 2013-09-22
| website = PHP.net
}}</ref> though using threads is made possible by the "pthreads" [[PHP Extension Community Library|PECL]] extension.<ref>{{cite web
| url = http://www.php.net/manual/en/intro.pthreads.php
| title = pthreads: Introduction (PHP Manual)
| access-date = 2013-09-22
| website = PHP.net
}}</ref><ref>{{cite web|url=https://pecl.php.net/package/pthreads |title=PECL :: Package :: pthreads |website=pecl.php.net |access-date=2014-02-09}}</ref>
A command line interface, php-cli, and two [[ActiveX]] [[Windows Script Host]] scripting engines for PHP have been produced.{{Citation needed|date=November 2023}}
=== Popularity and usage statistics ===
{{Pie chart
|radius = 160
<!-- PHP version 8 (26.5%) -->
|value1 = 0.56 <!-- Formula: Version 8.3 is used by 2.1% of all the websites who use PHP version 8, so 26.5 / 100 * 2.1 = 0.56 -->
|label1 = PHP 8.3: 2.10% of PHP 8
|color1 = #66FF66
|value2 = 4.85
|label2 = PHP 8.2: 18.3% of PHP 8
|color2 = #D4F4B4
|value3 = 10.79
|label3 = PHP 8.1: 40.7% of PHP 8
|color3 = #FEF8C6
|value4 = 10.31
|label4 = PHP 8.0: 38.9% of PHP 8
|color4 = #FDB3AB
<!-- PHP version 7 (57.2%) -->
|value5 = 39.47 <!-- Formula: Version 7.4 is used by 69% of all the websites who use PHP version 7, so 57.2 / 100 * 69 = 39.47 -->
|label5 = PHP 7.4: 69.0% of PHP 7
|color5 = red
|value6 = 7.55
|label6 = PHP 7.3: 13.2% of PHP 7
|color6 = MediumVioletRed
|value7 = 5.49
|label7 = PHP 7.2: 9.60% of PHP 7
|color7 = PaleVioletRed
|value8 = 2.23
|label8 = PHP 7.1: 3.90% of PHP 7
|color8 = IndianRed
|value9 = 2.46
|label9 = PHP 7.0: 4.30% of PHP 7
|color9 = DarkRed
<!-- PHP version 5 (16.2%) -->
|value10 = 8.7480
|label10 = PHP 5.6: 54.0% of PHP 5
|color10 = LightGrey
|value11 = 1.3608
|label11 = PHP 5.5: 8.40% of PHP 5
|color11 = DarkGrey
|value12 = 2.4948
|label12 = PHP 5.4: 15.4% of PHP 5
|color12 = Grey
|value13 = 2.4138
|label13 = PHP 5.3: 14.9% of PHP 5
|color13 = DimGrey
|value14 = 1.1016
|label14 = PHP 5.2: 6.80% of PHP 5
|color14 = LightSlateGrey
|value15 = 0.0648
|label15 = PHP 5.1: 0.40% of PHP 5
|color15 = SlateGrey
|value16 = 0.0162
|label16 = PHP 5.0: 0.10% of PHP 5
|color16 = DarkSlateGrey
<!-- PHP version 4 (0.2%) -->
|value17 = 0.1574
|label17 = PHP 4.4: 78.7% of PHP 4
|color17 = Violet
|value18 = 0.0370
|label18 = PHP 4.3: 18.5% of PHP 4
|color18 = BlueViolet
|value19 = 0.0032
|label19 = PHP 4.2: 1.60% of PHP 4
|color19 = DarkViolet
|value20 = 0.0016
|label20 = PHP 4.1: 0.80% of PHP 4
|color20 = DarkBlue
|value21 = 0.0006
|label21 = PHP 4.0: 0.30% of PHP 4
|color21 = Black
|caption = Usage share of PHP versions on {{Date|2024-03-23}}:<br> four months after PHP 8.3's release<ref name="PHP Usage Stats" /><ref>{{Cite web|url=https://w3techs.com/technologies/details/pl-php/4|title=Usage Statistics and Market Share of PHP Version 4 for Websites, March 2024|website=w3techs.com}}</ref><ref name="5 for Websites">{{Cite web|url=https://w3techs.com/technologies/details/pl-php/5|title=Usage Statistics and Market Share of PHP Version 5 for Websites, March 2024|website=w3techs.com}}</ref><ref>{{Cite web|url=https://w3techs.com/technologies/details/pl-php/7|title=Usage Statistics and Market Share of PHP Version 7 for Websites, March 2024|website=w3techs.com}}</ref><ref>{{Cite web|url=https://w3techs.com/technologies/details/pl-php/8|title=Usage Statistics and Market Share of PHP Version 8 for Websites, march 2024|website=w3techs.com}}</ref>
}}
PHP is used for [[Web content management system]]s including [[MediaWiki]],<ref>{{cite web|date=2010-01-25|title=Manual:Installation requirements#PHP|url=http://www.mediawiki.org/w/index.php?title=Manual:Installation_requirements&oldid=299556#PHP|access-date=2010-02-26|publisher=MediaWiki|quote=PHP is the programming language in which MediaWiki is written [...]}}</ref> [[WordPress]],<ref>{{cite web|title=About WordPress|url=http://wordpress.org/about/|access-date=2010-02-26|quote=WordPress was [...] built on PHP}}</ref> [[Joomla]],<ref>{{cite web|last=Kempkens|first=Alex|title=Joomla! — Content Management System to build websites & apps|url=http://www.joomla.org/about-joomla.html}}</ref> [[Drupal]],<ref>{{cite web|title=PHP and Drupal|date=16 September 2007|url=http://drupal.org/node/176052|access-date=2010-06-13|publisher=Drupal.org}}</ref> [[Moodle]],<ref>{{cite web|title=About|url=http://docs.moodle.org/en/About_Moodle|access-date=2009-12-20|publisher=Moodle.org}}</ref> [[eZ Publish]], [[eZ Platform]], and [[SilverStripe]].<ref>{{cite web|title=Server requirements of SilverStripe|url=http://doc.silverstripe.org/framework/en/installation/server-requirements|url-status=dead|archive-url=https://web.archive.org/web/20141128063118/http://doc.silverstripe.org/framework/en/installation/server-requirements|archive-date=28 November 2014|access-date=13 October 2014|quote=SilverStripe requires PHP 5.3.2+}}</ref>
{{As of|2013|1}}, PHP was used in more than 240 million [[website]]s (39% of those sampled) and was installed on 2.1 million [[web server]]s.<ref>{{cite web | url=http://news.netcraft.com/archives/2013/01/31/php-just-grows-grows.html | title=PHP just grows & grows | date=2013-01-31 | access-date=2013-04-01 | author=Ide, Andy}}</ref>
{{As of|2024|03|23}} (four months after PHP 8.3's release), PHP is used as the server-side programming language on 76.4% of websites where the language could be determined; PHP 7 is the most used version of the language with 57.2% of websites using PHP being on that version, while 26.6% use PHP 8, 16.2% use PHP 5 and 0.2% use PHP 4.<ref name="PHP Usage Stats">{{cite web |title=Usage statistics of PHP for websites |url=https://w3techs.com/technologies/details/pl-php |website=W3Techs – World Wide Web Technology Surveys |publisher=W3Techs |access-date=23 March 2024}}</ref>
== <span id="REGISTER-GLOBALS">Security</span> ==
In 2019, 11% of all vulnerabilities listed by the [[National Vulnerability Database]] were linked to PHP;<ref name="CVE">{{cite web | url=https://nvd.nist.gov/vuln/search/statistics?form_type=Basic&results_type=statistics&query=PHP&queryType=phrase&search_type=all | title=National Vulnerability Database (NVD) Search Vulnerabilities Statistics | access-date=2019-11-22}}</ref> historically, about 30% of all vulnerabilities listed since 1996 in this database are linked to PHP. Technical security flaws of the language itself or of its core libraries are not frequent (22 in 2009, about 1% of the total although PHP applies to about 20% of programs listed).<ref name="PHP-related vulnerabilities on the National Vulnerability Database">{{cite web
| url=http://www.coelho.net/php_cve.html
| title=PHP-related vulnerabilities on the National Vulnerability Database
| date=2012-07-05
| access-date=2013-04-01
}}</ref> Recognizing that programmers make mistakes, some languages include [[taint checking]] to automatically detect the lack of [[data validation|input validation]] which induces many issues. Such a feature is being developed for PHP,<ref>{{Cite web|url=https://wiki.php.net/rfc/taint|title=PHP: rfc:taint|website=wiki.php.net}}</ref> but its inclusion into a release has been rejected several times in the past.<ref>{{cite web
| url=http://derickrethans.nl/files/meeting-notes.html#sand-boxing-or-taint-mode <!-- formerly at https://php.net/~derick/meeting-notes.html#sand-boxing-or-taint-mode -->
| title=Developer Meeting Notes, Nov. 2005}}</ref><ref>{{cite web
|url = http://devzone.zend.com/article/2798-Zend-Weekly-Summaries-Issue-368#Heading1
|title = Taint mode decision, November 2007
|url-status = dead
|archive-url = https://web.archive.org/web/20090226124957/http://devzone.zend.com/article/2798-Zend-Weekly-Summaries-Issue-368#Heading1
|archive-date = 2009-02-26
}}</ref>
There are advanced protection patches such as [[Suhosin]] and [[hardening (computing)|Hardening]]-Patch, specially designed for web hosting environments.<ref>{{cite web
| title=Hardened-PHP Project
| url=http://www.hardened-php.net
| date=2008-08-15
| access-date=2019-08-22
| archive-url=https://web.archive.org/web/20190224012812/http://www.hardened-php.net/
| archive-date=2019-02-24
| url-status=dead
}}</ref>
Historically, old versions of PHP had some configuration parameters and default values for such runtime settings that made some PHP applications prone to security issues. Among these, <code>[[magic quotes|magic_quotes_gpc]]</code> and <code>register_globals</code><ref name="register-globals">{{cite web
| url = https://php.net/manual/en/security.globals.php
| title = Security: Using Register Globals | work = PHP Manual
| access-date = 2013-09-22
| publisher = PHP.net
}}</ref> configuration directives were the best known; the latter made any URL parameters become PHP variables, opening a path for serious security vulnerabilities by allowing an attacker to set the value of any uninitialized global variable and interfere with the execution of a PHP script. Support for "[[magic quotes]]" and "register globals" settings has been deprecated since PHP 5.3.0, and removed from PHP 5.4.0.<ref name="magic-quotes">{{cite web
| url = http://www.php.net/manual/en/security.magicquotes.php
| title = Magic Quotes | work = PHP Manual
| access-date = 2014-01-17
| publisher = PHP.net
}}</ref>
Another example for the potential runtime-settings vulnerability comes from failing to disable PHP execution (for example by using the <code>engine</code> configuration directive)<ref>{{cite web
| url = http://www.php.net/manual/en/apache.configuration.php#ini.engine
| title = 'engine' configuration directive
| work = PHP: Runtime Configuration
| access-date = 2014-02-13
| publisher = PHP.net
}}</ref> for the directory where uploaded files are stored; enabling it can result in the execution of malicious code embedded within the uploaded files.<ref>{{cite web
| url = http://devzone.zend.com/1008/php-security-exploit-with-gif-images/
| title = PHP Security Exploit With GIF Images
| date = 2007-06-22
| access-date = 2013-09-22
| archive-url = https://web.archive.org/web/20130927162421/http://devzone.zend.com/1008/php-security-exploit-with-gif-images/
| archive-date = 2013-09-27
| url-status = dead
}}</ref><ref>{{cite web
| url = http://www.phpclasses.org/blog/post/67-PHP-security-exploit-with-GIF-images.html
| title = PHP security exploit with GIF images
| date = 2007-06-20 | access-date = 2013-09-22
| publisher = PHP Classes blog
}}</ref><ref>{{cite web
|url = http://ha.ckers.org/blog/20070604/passing-malicious-php-through-getimagesize/
|title = Passing Malicious PHP Through getimagesize()
|date = 2007-06-04
|access-date = 2013-09-22
|url-status = dead
|archive-url = https://web.archive.org/web/20130921222424/http://ha.ckers.org/blog/20070604/passing-malicious-php-through-getimagesize
|archive-date = 2013-09-21
}}</ref> The best practice is to either locate the image directory outside of the document root available to the web server and serve it via an intermediary script or disable PHP execution for the directory which stores the uploaded files.{{Citation needed|date=November 2023}}
Also, enabling the dynamic loading of PHP extensions (via <code>enable_dl</code> configuration directive)<ref>{{cite web
| url = http://www.php.net/manual/en/info.configuration.php#ini.enable-dl
| title = 'enable_dl' configuration directive
| work = PHP: Runtime Configuration
| access-date = 2014-02-13
| publisher = PHP.net
}}</ref> in a [[shared web hosting]] environment can lead to security issues.<ref>{{cite web
| url = https://php.net/manual/en/function.dl.php
| title = PHP function reference: dl()
| access-date = 2013-09-22
| publisher = PHP.net
}}</ref><ref>{{cite web
| url = http://www.webhostingtalk.com/showthread.php?t=514779
| title = My host won't fix their Trojan
| access-date = 2013-09-22
| publisher = WebHosting Talk
}}</ref>
Implied [[type conversion]]s that result in different values being treated as equal, sometimes against the programmer's intent, can lead to security issues. For example, the result of the comparison {{nowrap|1=<code>'0e1234' == '0'</code>}} is <code>true</code>, because strings that are parsable as numbers are converted to numbers; in this case, the first compared value is treated as [[scientific notation]] having the value ({{val|0|e=1234}}), which is zero. Errors like this resulted in authentication vulnerabilities in [[Simple Machines Forum]],<ref>{{cite web|url=http://raz0r.name/vulnerabilities/simple-machines-forum/|title= Simple Machines Forum <= 2.0.3 Admin Password Reset|author=Raz0r|date = 25 January 2013}}</ref> [[Typo3]]<ref>{{cite web|url=http://blog.nibblesec.org/2010/12/typo3-sa-2010-020-typo3-sa-2010-022.html|title=TYPO3-SA-2010-020, TYPO3-SA-2010-022 EXPLAINED|author=Nibble Security}}</ref> and [[phpBB]]<ref>{{cite web|url=http://ahack.ru/articles/cryptographic-security-and-php-applications.htm |title=Криптостойкость и небезопасное сравнение |website=Ahack.ru |language=ru }}</ref> when [[MD5]] [[password hashing|password hashes]] were compared. The recommended way is to use [https://secure.php.net/hash_equals hash_equals()] (for [[timing attack]] safety), <code>[[strcmp]]</code> or the identity operator (<code>===</code>), as {{nowrap|1=<code>'0e1234' === '0'</code>}} results in <code>false</code>.<ref>{{cite web|url=https://www.php.net/manual/en/language.operators.comparison.php |title=Comparison operators |publisher=PHP.net}}</ref>
In a 2013 analysis of over 170,000 [[website defacement]]s, published by [[Zone-H]], the most frequently (53%) used technique was the exploitation of [[file inclusion vulnerability]], mostly related to insecure usage of the PHP language constructs <code>include</code>, <code>require</code>, and <code>allow_url_fopen</code>.<ref>{{cite web | url=https://ipsec.pl/web-application-security/most-common-attacks-web-applications.html | title=Most common attacks on web applications | publisher=IPSec.pl | date=2013 | access-date=2015-04-15 | first=Pawel |last=Krawczyk | archive-url=https://web.archive.org/web/20150415150236/https://ipsec.pl/web-application-security/most-common-attacks-web-applications.html | archive-date=2015-04-15 | url-status=dead }}</ref><ref>{{cite web | url=https://ipsec.pl/application-security/2013/so-what-are-most-critical-application-flaws-new-owasp-top-10.html | title=So what are the "most critical" application flaws? On new OWASP Top 10 | publisher=IPSec.pl | date=2013 | access-date=2015-04-15 |first=Pawel |last=Krawczyk }}</ref>
{{As of|2024|03|23|post=,}} (4 months after PHP 8.3 release) W3Techs reports that 83.9% of websites using PHP, use versions 8.0 or older (which are [[End-of-life (product)#Computing|no longer supported]] by The PHP Development Team).<ref>{{Cite web|url=https://w3techs.com/technologies/details/pl-php/all/all|title=Usage Statistics and Market Share of PHP for Websites, March 2024|website=w3techs.com|access-date=2024-03-23}}</ref> PHP Version 5 is still used by 16.2% of all websites.<ref name="5 for Websites"/> It is highly recommended to migrate to PHP 8.1 or later and use <code>random_int()</code><ref>{{cite web | url=https://php.net/random_int | title=PHP: Random_int - Manual }}</ref> instead of <code>rand()</code><ref>{{cite web | url=https://php.net/rand | title=PHP: Rand - Manual }}</ref> or <code>mt_rand()</code>,<ref>{{cite web | url=https://php.net/mt_rand | title=PHP: Mt_rand - Manual }}</ref> as the latter functions are not cryptographically secure. There are two attacks that can be performed over PHP entropy sources: "seed attack" and "state recovery attack".{{Citation needed|date=November 2023}} With current{{when|date=March 2023}} GPU technologies, an attacker can perform up to 2{{sup|30}} MD5 calculations per second with a $250 GPU, while with an additional $500 can reach up to 2{{sup|32}} calculations.<ref>{{Cite web|url=https://www.readkong.com/page/i-forgot-your-password-randomness-attacks-against-php-2199669|title=I Forgot Your Password: Randomness Attacks Against PHP Applications|website=www.readkong.com}}</ref> In combination with a "[[birthday attack]]" this can lead to serious security vulnerabilities.{{Citation needed|date=November 2023}}
== See also ==
{{Portal|Computer programming|Free and open-source software}}
{{Div col|colwidth=25em}}
* [[Comparison of programming languages]]
* [[List of Apache–MySQL–PHP packages]]
* [[List of PHP accelerators]]
* [[List of PHP editors]]
* [[PEAR]] (PHP Extension and Application Repository)
* [[PHP accelerator]]
* [[Template processor]]
* [[XAMPP]] (free and open-source cross-platform web server solution stack package)
* [[Zend Server]]
{{div col end}}
== References ==
{{Reflist}}
== Further reading ==
{{Spoken Wikipedia|En-PHP.ogg|date=2011-11-23}}
* {{cite journal |quote=What's the Absolute Minimum I Must Know About PHP? |url= https://www.bloomberg.com/graphics/2015-paul-ford-what-is-code/ |title=What is Code? |first=Paul |last=Ford |date=June 11, 2015 |journal=[[Bloomberg Businessweek]]}}
==External links==
* {{Official website}}
* {{Curlie|Computers/Programming/Languages/PHP}}
{{Navboxes|list=
{{PHP}}
{{Web interfaces}}
{{Programming languages}}
{{FOSS}}
}}
{{Sister bar|wikt=no|commons=Category:PHP|v=Topic:PHP|n=no|q=no|s=no|b=PHP Programming|voy=no|mw=PHP}}
{{Authority control}}
[[Category:PHP| ]]
[[Category:1995 software]]
[[Category:Articles with example PHP code]]
[[Category:Class-based programming languages]]
[[Category:Cross-platform software]]
[[Category:Dynamic programming languages]]
[[Category:Dynamically typed programming languages]]
[[Category:Filename extensions]]
[[Category:Free compilers and interpreters]]
[[Category:High-level programming languages]]
[[Category:Internet terminology]]
[[Category:Object-oriented programming languages]]
[[Category:PHP software]]
[[Category:Procedural programming languages]]
[[Category:Programming languages]]
[[Category:Programming languages created in 1995]]
[[Category:Scripting languages]]
[[Category:Software using the PHP license]]
[[Category:Text-oriented programming languages]]' |