PHP

PHP · Browse articles by tag (only tags with 5+ articles get a page).

ProgrammingIntermediateSeries 1

Build a Todo App with PDO

A complete PHP project: SQLite schema, add/toggle/delete over POST, CSRF tokens, Post/Redirect/Get with flash messages, escaped views, and a pre-deploy checklist.

ProgrammingIntermediateSeries 1

Composer and Namespaces in PHP

Dependency management and PSR-4 autoloading: composer.json structure, namespace mapping, version constraints, the lock file, scripts and autoloader optimisation.

ProgrammingBeginnerSeries 3

PHP Conditionals and Loops

if versus match versus switch, when to use for, foreach and while, break/continue with nesting levels, and the alternative colon syntax that keeps HTML templates readable.

ProgrammingIntermediateSeries 5

Debugging and Logging in PHP

Two error configurations, custom handlers for errors and exceptions, JSON logs with request IDs, Xdebug breakpoints, and a triage order for the white screen.

ProgrammingBeginnerSeries 7

Errors and Exceptions in PHP

How PHP separates errors from exceptions, the Throwable hierarchy, try/catch/finally, which exception class to throw, JSON_THROW_ON_ERROR, a global handler, and production error settings.

ProgrammingBeginnerSeries 6

Reading and Writing Files in PHP

file_get_contents and file_put_contents for small files, fgets streaming for large ones, file locking for concurrent writes, directory iteration with SPL, and why paths must start from __DIR__.

ProgrammingBeginnerSeries 5

Handling Forms and Requests in PHP

Work with $_GET and $_POST safely: choose the right method, validate with filter_var, escape output with htmlspecialchars, and follow Post/Redirect/Get to stop duplicate submissions.

ProgrammingBeginnerSeries 4

PHP Functions, Types and Scope

Declare parameter and return types, use defaults and named arguments, understand pass-by-value versus reference and object handles, plus closures, arrow functions and static locals.

ProgrammingIntermediateSeries 3

Objects and the Type System in PHP

Constructor promotion, readonly properties, backed enums, interfaces versus abstract classes, traits, union and nullable types, and why strict_types comes first.

ProgrammingIntermediateSeries 2

PDO and Prepared Statements

Safe database access with PDO: DSN and connection options, exception mode, named and positional parameters, transactions, and where placeholders stop working.

ProgrammingIntermediateSeries 2

A JSON REST API with PDO

A minimal REST API without a framework: method dispatch, one JSON error shape, input validation, pagination and sort whitelists, status codes, and curl checks.

ProgrammingBeginnerSeries 8

PHP Sessions and Cookies

Start and use sessions, destroy them properly, regenerate the ID on login to prevent fixation, set cookies with secure, httponly and samesite, and never trust cookie contents.

ProgrammingBeginnerSeries 2

PHP Strings and Arrays

Indexed and associative arrays, how foreach really iterates, array_map/filter/reduce, the difference between + and array_merge, and the string functions you need — including mb_* for UTF-8.

ProgrammingIntermediateSeries 4

Templates, Layouts and Escaping in PHP

Split querying from output with one small render function: layouts, partials, htmlspecialchars-based escaping, alternative syntax, and what views must never do.

ProgrammingIntermediateSeries 6

Unit Testing PHP with PHPUnit

Install PHPUnit 11 with Composer, choose assertions that actually fail, use data providers and test doubles, test PDO code on SQLite, and run coverage in CI.

ProgrammingBeginnerSeries 1

PHP Variables and Data Types

Variable syntax and scope, the scalar types, strings and arrays, why loose comparison bites, what declare(strict_types=1) actually changes, and the falsy values that surprise newcomers.