NightFox

NightFox

PHP Programming

PHP gets made fun of a lot, and some of that was earned back in the day. But it's still a great fit for server-rendered websites, APIs, background jobs, internal tools, and business software, and it's what I reach for first. These notes start with the language and work up to running PHP safely in production.

Practical PHP, without hiding the important parts

I first used PHP to modify PHP-Nuke modules in the mid-2000s. The language and ecosystem have changed dramatically since then: strict types, modern object syntax, Composer, static analysis, robust testing tools, and mature deployment patterns make modern PHP a very different environment.

The examples here are plain PHP on purpose, so you can actually see the request lifecycle, validation, SQL, authentication, and error handling instead of having a framework do it behind a curtain. Everything carries straight over if you use Laravel or Symfony later.

Recommended order: Syntax and types → conditionals → arrays and functions → forms → PDO → sessions → security → project structure → testing → deployment.

A minimal modern starting point

<?php
declare(strict_types=1);

require dirname(__DIR__) . '/vendor/autoload.php';

use App\Infrastructure\Database;

$pdo = Database::connect();

$stmt = $pdo->prepare(
    'SELECT id, name, status FROM customers WHERE status = :status ORDER BY name'
);
$stmt->execute(['status' => 'active']);

header('Content-Type: application/json; charset=utf-8');
echo json_encode($stmt->fetchAll(), JSON_THROW_ON_ERROR);

Habits that pay off

  • Enable strict types in new source files.
  • Use parameter and return types wherever they clarify intent.
  • Treat every request value as untrusted input.
  • Use prepared statements and explicit transactions.
  • Store configuration outside the public document root.
  • Log enough context to diagnose failures without logging secrets.
  • Automate syntax checks, tests, and database migrations before deployment.

Last Modified: October 12, 2026, 11:46 am