Tag: php
Loop Style Preferences
PHP 7.4+
Choose the clearest loop construct for the job: foreach for collections, for with index when position matters, while for condition-driven iteration.
1mo ago
Style beginner
HTTP Cookies in PHP
PHP 7.3+
3
Cookies are small key-value pairs sent by the server via Set-Cookie and echoed back by the browser on every request — PHP sets them with setcookie() before any output, with Secure, HttpOnly, and SameSite flags controlling safety.
3mo ago
PHP beginner
MySQL charset=utf8mb4
PHP 5.1+
The correct MySQL character set for full Unicode support — including emoji and supplementary characters that the older utf8 charset cannot store.
3mo ago
PHP beginner
MySQL DSN (Data Source Name)
PHP 5.1+
The connection string passed to PDO specifying the database driver, host, port, database name, and charset.
3mo ago
PHP beginner
PDO Error Handling
PHP 5.1+
PDO has three error modes — silent, warning, and exception — controlling how database errors surface.
3mo ago
PHP beginner
PDO Fetch Modes
PHP 5.1+
Constants controlling how PDO returns rows — as arrays, objects, or custom classes.
3mo ago
PHP beginner
PDO lastInsertId()
PHP 5.1+
Returns the auto-increment ID generated by the most recent INSERT statement.
3mo ago
PHP beginner
PDO Named Placeholders
PHP 5.1+
Named parameters (:name) in prepared statements — more readable than positional ? placeholders for queries with multiple parameters.
3mo ago
PHP beginner
PDO query() vs prepare()
PHP 5.1+
PDO query() executes raw SQL immediately — prepare() parameterises it. query() must never include user-controlled values.
CWE-89 OWASP A3:2021
3mo ago
PHP beginner
9.8
PDOStatement::rowCount()
PHP 5.1+
Returns the number of rows affected by the last DELETE, INSERT, or UPDATE — unreliable for SELECT.
3mo ago
PHP beginner
Anchors & Word Boundaries
PHP 5.3+
1
Zero-width assertions that match positions rather than characters — ^ matches start of string, $ matches end, \b matches a word boundary — ensuring patterns match in the correct location.
3mo ago
Regex beginner
Arrow Functions fn() => (PHP 7.4)
PHP 7.4+
PHP 7.4 arrow functions (fn($x) => $x * $factor) are short closures that automatically capture outer scope — no more use($var) boilerplate.
3mo ago
PHP beginner
Capture Groups & Backreferences
PHP 5.3+
4
Parentheses in a regex pattern create capture groups that store matched substrings for extraction or reuse — backreferences let you match the same text again later in the pattern or replacement string.
3mo ago
Regex beginner
Debugging PHP
PHP 5.0+
8
Systematic techniques for finding and fixing PHP bugs — from var_dump and error logs to Xdebug step-debugging, with the guiding principle of narrowing down where incorrect behaviour first appears.
3mo ago
PHP beginner
each() & list() — Deprecated Iteration
PHP 3.0+
each() was deprecated in PHP 7.2 and removed in PHP 8 — replace while(list($k,$v)=each($arr)) with foreach. list() itself is still valid as [] destructuring.
3mo ago
PHP beginner
ereg() / eregi() — POSIX Regex Removed in PHP 7
PHP 3.0+
ereg() and eregi() were POSIX regex functions removed in PHP 7.0 — replace with preg_match() (PCRE) which is faster, more powerful, and the standard since PHP 4.
3mo ago
PHP beginner
Error Logging
PHP 4.0+
2
Recording application errors, exceptions, and diagnostic information to persistent storage — essential for diagnosing production issues where display_errors must be off and errors are invisible to users.
3mo ago
PHP beginner
Error Reporting & Display
PHP 4.0+
1
PHP's error_reporting level and display_errors directive control which errors are shown and where — development needs E_ALL with display on; production needs E_ALL with display off and logging on.
3mo ago
PHP beginner
Exception Handling Introduced (PHP 5)
PHP 5.0+
PHP 5 introduced try/catch/finally and the Exception class — replacing PHP 4's procedural error handling with structured exception-based patterns.
3mo ago
PHP beginner
File Permissions
PHP 4.0+
Unix permission bits (owner/group/world read-write-execute) that control which processes can read, write, or execute files — misconfigured permissions are a common PHP deployment and security issue.
3mo ago
PHP beginner