Programming languages

PHP

A server-side web language: it powers WordPress, Laravel and a large part of the internet.

What it is

Rasmus Lerdorf created PHP in 1995 as a set of scripts for his own homepage. Today it is a full language with classes, types, attributes and a JIT.

The execution model is simple: every request starts from a clean state, so horizontal scaling is predictable. Packages come from Packagist via Composer.

Modern PHP (8.x) has optional strict typing, enums, readonly properties and named arguments. The best known frameworks are Laravel and Symfony. WordPress, Drupal and Magento are also PHP.

Use it when

  • Websites and web apps, especially on Laravel or Symfony.
  • Working with WordPress, WooCommerce, Magento and other PHP systems.
  • Cheap, widespread hosting: PHP is supported almost everywhere.

Avoid it when

  • Long-running processes, websockets and high-concurrency real-time: Node.js, Go or Elixir fit better.
  • Non-web tasks: desktop, systems programming, ML.

Key concepts

Composer
The dependency manager, with PSR-4 class autoloading.
PHP-FPM
A process pool that runs PHP behind nginx or Apache.
Request lifecycle
Each request runs from scratch and shares no state with the previous one.
PSR
Community standards (PHP-FIG): code style, autoloading, interfaces.
Enums and types
PHP 8 has enums, union types, readonly and constructor promotion.

Example

An enum and match in PHP 8.

Interview questions

  1. 1. How does == differ from === in PHP?

    == compares with type juggling, while === also requires the same type. PHP 8 made == stricter for strings and numbers, but === is still safer.

  2. 2. What are Composer and PSR-4?

    Composer manages dependencies. PSR-4 is an autoloading standard that maps namespaces to directories, so you do not require every class.

  3. 3. How does PHP keep state between requests?

    It does not by itself. State lives in sessions (files, Redis), a database or a cache. Every request starts from zero.

  4. 4. What is new in PHP 8?

    JIT, union types, named arguments, attributes, match, the nullsafe operator ?->, constructor promotion, and in 8.1 enums and readonly.

Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).