Skip to main content

PHP

PHP (PHP: Hypertext Preprocessor) is a server-side scripting language designed for web development. Despite criticism, it powers a significant portion of the web, including WordPress, which runs over 40% of all websites.

Key Characteristics

  • Server-side: Executes on the web server
  • Embedded in HTML: Can mix with markup (though modern PHP doesn't)
  • Loosely typed: Dynamic typing with optional type hints (PHP 7+)
  • Request-based: Fresh state on each request (shared-nothing)
  • Extensive standard library: Built-in functions for common tasks

Modern PHP (8.x)

PHP has evolved significantly:

// Constructor property promotion
class User {
public function __construct(
public readonly string $name,
public readonly string $email,
) {}
}

// Named arguments
$user = new User(name: 'Alice', email: 'alice@example.com');

// Match expressions
$status = match($code) {
200 => 'OK',
404 => 'Not Found',
500 => 'Server Error',
default => 'Unknown',
};

// Null-safe operator
$city = $user?->address?->city;
FrameworkStyleBest For
LaravelFull-stack, elegantMost PHP projects
SymfonyComponents, enterpriseLarge applications
SlimMicro-frameworkSimple APIs
LaminasEnterpriseZend successor

What We Like

  • Mature ecosystem: Decades of packages and patterns
  • Laravel: Modern, developer-friendly framework
  • Hosting: Runs anywhere, cheap hosting options
  • WordPress: Massive CMS ecosystem
  • PHP 8: Modern language features, JIT compiler

What We Don't Like

  • Inconsistent standard library: Function naming and parameter order
  • Legacy stigma: Old PHP code gives the language a bad reputation
  • Deployment: Requires web server configuration
  • Not async by default: Request-based model limits concurrency

When to Use PHP

  • WordPress development or customisation
  • Quick web applications with Laravel
  • Existing PHP codebase maintenance
  • Budget-conscious hosting requirements
  • Teams with PHP expertise

Best Practices

  1. Use a framework: Laravel or Symfony, not raw PHP
  2. Use Composer: Modern dependency management
  3. Enable strict types: declare(strict_types=1);
  4. Follow PSR standards: PSR-4 autoloading, PSR-12 coding style
  5. Use static analysis: PHPStan or Psalm