PHP
PHP: Hypertext Preprocessor
In short
PHP is a dynamically typed scripting language designed for web development that runs on the server to generate HTML pages and respond to browser requests.
What is PHP?
PHP is a scripting language for web development created by Rasmus Lerdorf in 1994, originally as a set of tools for his personal home page. Today the name is a recursive acronym for "PHP: Hypertext Preprocessor." PHP runs on the server: when a browser requests a page, the web server passes the request to PHP, which runs the script and sends back the resulting HTML or JSON. PHP code can even be embedded directly inside HTML between <?php and ?> tags.
PHP is dynamically typed, but modern versions support type declarations for function parameters, return values, and class properties, and declare(strict_types=1) turns off automatic type conversion for those checks. Memory is managed automatically with reference counting and a cycle collector. In the traditional model, each request starts with a clean slate and all its memory is released when the response is sent, which keeps applications simple to reason about and to scale.
PHP powers a large share of websites, including many content management systems, blogs, online stores, and web APIs, and it is usually paired with a SQL database. PHP works like a restaurant kitchen: the customer (the browser) receives only the finished dish (the HTML), never the recipe (the PHP code). Recent releases, starting with PHP 8, added a JIT compiler, union types, enums, match expressions, and readonly properties.
PHP is sometimes confused with JavaScript because both are closely tied to the web. PHP runs on the server and the browser never sees its code, while JavaScript mostly runs in the browser to make pages interactive, although it can also run on servers. Older PHP versions were criticized for inconsistent functions and loose type juggling, but versions 7 and 8 brought major speed improvements and much stricter typing options.
Key takeaways
- PHP runs on the server and sends only its output, such as HTML or JSON, to the browser.
- It is dynamically typed, with optional type declarations and a strict types mode.
- Memory is managed automatically and released at the end of each request.
- It powers a large share of websites, including many content management systems.
- Modern PHP 8 adds features like enums,
matchexpressions, and a JIT compiler.
Example
<?php
declare(strict_types=1);
// Type declarations reject wrong argument types when called
function greet(string $name, int $visits): string
{
return "Hello, {$name}! This is visit number {$visits}.";
}
$name = htmlspecialchars($_GET['name'] ?? 'guest'); // Escape user input
echo greet($name, 3);Readers ask
Is PHP still used?
Yes. PHP still runs a large share of the web, especially sites built on popular content management systems, and the language gets a new release every year with new features and performance improvements.
What does PHP stand for?
PHP originally stood for Personal Home Page. Today it is a recursive acronym for PHP: Hypertext Preprocessor, where the first letter refers back to the name itself.
What is the difference between PHP and JavaScript?
PHP runs on the server and sends the finished result to the browser, while JavaScript mainly runs inside the browser to make pages interactive. JavaScript can also run on servers with runtimes such as Node.js.
See also
- Web ServerBackend & APIs, p. 46A web server is software, or the machine running it, that accepts HTTP requests from browsers and other clients and responds with pages, files, or data.
- HTMLWeb Development, p. 18HTML is the markup language that defines the structure and content of web pages, such as headings, paragraphs, links, images, and forms.
- HTTPWeb Development, p. 19HTTP is the protocol that browsers, apps, and servers use to exchange web pages and data through a simple cycle of requests and responses.
- JavaScriptWeb Development, p. 24JavaScript is the programming language that runs in web browsers to make pages interactive, and it also runs on servers through runtimes like Node.js.
- SessionBackend & APIs, p. 43A session is a way for a server to remember a user across many requests, usually by keeping their data on the server and giving the browser a session ID.
- SQL InjectionSecurity, p. 40SQL injection is an attack where user input is treated as part of a database query, letting an attacker read, change, or delete data they should not reach.
- LaravelBackend & APIs, p. 27Laravel is a PHP framework for full web applications, with an elegant syntax and built-in routing, the Eloquent ORM, authentication, queues and migrations.
Spotted a mistake or something missing on this page?Suggest an edit