Skill-
Forge
Learn
Notes
Language & Framework notes
CS Core Subjects
OS, DBMS, Networks, OOP & more
System Design
Architecture & High-Scale
Roadmaps
Guided developer learning paths
Cheat Sheets
Quick syntax references
Resources
Curated books, guides & links
Practice
Problems
DSA & coding challenges
Quizzes
Test your knowledge
Algorithms
Explanations & visualizations
Git Visualizer
Interactive Git graph & CLI playground
Aptitude
Placement & logic prep
Formula Simulators
Real-time quant equation simulators
Build
Projects Hub
Step-by-step real world projects
Resume Builder
ATS-friendly resumes, live preview & score
Tools
Online compilers & utilities
Skills
Core professional & tech skills
Error Encyclopedia
Search
⌘K
Install App
Start Learning
Menu
Learn
Notes
CS Core Subjects
System Design
Roadmaps
Cheat Sheets
Resources
Practice
Problems
Quizzes
Algorithms
Git Visualizer
Aptitude
Formula Simulators
Build
Projects Hub
Resume Builder
Tools
Skills
Error Encyclopedia
Search
Install Skill-Forge App
Appearance
Start Learning
Skip to main content
Cheatsheets
18 sections
61 cards
PHP 8.3 · PDO · Composer · 2025
🐘
PHP Cheat Sheet
Syntax · Arrays · OOP · PDO · Sessions · Composer · Regex · Best Practices
Browse sections
Shortcuts
?
Hide Sidebar
Search cheatsheet sections
/
or
⌘K
Progress
0%
Table of contents
Shortcuts
?
⚡
Syntax & Data Types
📌
Variables & Scope
🔢
Operators
🔀
Control Flow
🧩
Functions
📦
Arrays & Array Functions
✍️
String Functions
🏛️
Object-Oriented PHP
✨
PHP 8 Modern Features
💥
Error Handling & Exceptions
📁
File I/O
🗄️
Database — PDO
📋
Forms & Superglobals
🍪
Sessions & Cookies
📅
Date & Time
🔍
Regular Expressions
📦
Composer & Namespaces
📋
Quick Reference & Gotchas
J
K
Jump
/
Search
Esc
Clear
⚡
Syntax & Data Types
Fundamentals
PHP Tags & Output
Data Types
Type Juggling & Casting
Falsy Values ⭐
📌
Variables & Scope
$, Constants, Scope
Variables
Constants
Variable Scope
String Interpolation
🔢
Operators
All Operator Types
Operator Reference 🔥
Spaceship & Null Coalescing
🔀
Control Flow
if · loops · match · switch
if / elseif / else
match Expression (PHP 8) ⭐
switch
Loops
🧩
Functions
Declarations · Closures · Arrow
Function Declarations & Type Hints 🔥
Closures (Anonymous Functions)
Arrow Functions (PHP 7.4+) ⭐
First-class Callables (PHP 8.1)
Named Arguments (PHP 8.0) ⭐
📦
Arrays & Array Functions
Indexed · Associative · Multi
Array Creation
Add / Remove
Search & Check
Sort Functions
Functional Array Methods 🔥
Destructuring
✍️
String Functions
Most Used Functions
String Functions Reference 🔥
sprintf Format Specifiers
Password Security ⭐
🏛️
Object-Oriented PHP
Classes · Interfaces · Traits
Complete Class Reference 🔥
Inheritance
Interfaces & Traits
Enums (PHP 8.1) ⭐
✨
PHP 8 Modern Features
8.0 · 8.1 · 8.2 · 8.3
PHP 8.x Feature Matrix 🔥
Attributes (PHP 8.0)
Fibers (PHP 8.1)
💥
Error Handling & Exceptions
try · catch · finally
try / catch / finally
Exception Hierarchy
<b>Throwable</b> — top interface (PHP 7+)
<b>Error</b> — engine errors (TypeError, ParseError, ArithmeticError…)
<b>Exception</b> — user exceptions
<b>RuntimeException</b> — during execution
<b>LogicException</b> — programming mistakes
<b>InvalidArgumentException</b>
<b>BadMethodCallException</b>
<b>OverflowException</b>
Error Levels & Handlers
📁
File I/O
Read · Write · Filesystem
Read & Write
Filesystem Functions
CSV & JSON Files
🗄️
Database — PDO
Prepared Statements · Transactions
PDO Connection & Queries 🔥
Fetch Modes
SQL Injection Prevention
❌ Never interpolate user input into SQL strings
📋
Forms & Superglobals
$_GET · $_POST · $_FILES
Superglobals Reference 🔥
Form Input Handling
File Uploads
CSRF Protection
🍪
Sessions & Cookies
State Management
Sessions
Cookies
📅
Date & Time
date · DateTime · Carbon
date() Format Codes
DateTime OOP (preferred) ⭐
🔍
Regular Expressions
PCRE Functions
Regex Functions
Pattern Quick Reference
📦
Composer & Namespaces
PSR-4 · Autoloading
Composer CLI
composer.json
Namespaces (PSR-4)
Version Constraints
📋
Quick Reference & Gotchas
Cheat Table + Pitfalls
Most Used Built-in Functions 🔥
Classic PHP Gotchas ⭐
<b>Loose comparisons</b> — <code>0 == "foo"</code> is <code>false</code> in PHP 8 but was <code>true</code> in PHP 7. Always use <code>===</code>.
<b>array_filter keys</b> — preserves original keys! Always follow with <code>array_values()</code> if you need re-indexed.
<b>foreach by value</b> — copies the array; use <code>&$val</code> to modify in place.
<b>Headers must come first</b> — <code>header()</code>, <code>setcookie()</code>, <code>session_start()</code> must be before any output.
<b>strpos returns 0</b> — if needle is at position 0, result is <code>0</code> (falsy!). Use <code>=== false</code> check.
<b>Type juggling in switch</b> — switch uses loose <code>==</code>; use <code>match</code> for strict comparison.
<b>Integer division</b> — <code>7 / 2 = 3.5</code> (float). Use <code>intdiv(7,2)</code> or cast <code>(int)(7/2)</code>.
<b>References in loops</b> — after <code>foreach ($arr as &$v)</code>, <code>unset($v)</code> after the loop or the last element gets corrupted.
<b>Null vs empty</b> — <code>isset()</code> returns false for null; <code>empty()</code> returns true for 0, "", "0", [], null.
<b>Date timezone</b> — always set <code>date_default_timezone_set('Asia/Kolkata')</code> or in php.ini.
<b>String functions are not MB-safe</b> — use <code>mb_*</code> variants (mb_strlen, mb_substr) for Unicode.
Security Checklist ⭐
Always use <b>prepared statements</b> — never interpolate user data into SQL
Escape output with <b>htmlspecialchars()</b> — prevents XSS
Use <b>password_hash / password_verify</b> — never md5/sha1 for passwords
Validate file uploads with <b>finfo</b> (real MIME) — not <code>$_FILES['type']</code>
Set <b>httponly + secure + samesite</b> flags on all cookies
<b>session_regenerate_id(true)</b> after login — prevent session fixation
Use <b>random_bytes / random_int</b> — not rand() for security tokens
Validate & sanitize ALL <b>$_GET / $_POST</b> input with filter_var
Implement <b>CSRF tokens</b> in all state-changing forms
Never expose <b>error details</b> to users — log them server-side