
PHP
- 8 installs
- 33 repo stars
- Updated April 26, 2026
- bighardperson/computer-science-skills-collection
PHP is a skill that provides coding guidelines to write solid PHP while avoiding type-juggling traps, array quirks, and security pitfalls.
About
PHP is a coding-guidelines skill that helps write solid PHP by avoiding type-juggling traps, array quirks, and common security pitfalls. It provides critical rules on strict comparison, prepared statements, and output escaping, plus topic files on types, arrays, OOP, strings, errors, security, and modern PHP 8+ features. A developer references it while writing or reviewing PHP code.
- PHP coding rules for type juggling, arrays, OOP, and strings
- Flags common security pitfalls: SQL injection, XSS, CSRF
- Covers PHP 8+ features like attributes, named args, and match
PHP by the numbers
- 8 all-time installs (skills.sh)
- Ranked #52 of 65 PHP & Laravel skills by installs in the Skillselion catalog
- Data as of Jul 30, 2026 (Skillselion catalog sync)
PHP capabilities & compatibility
- Capabilities
- code review · secure coding · refactoring
- Use cases
- code review · refactoring · security audit
- Platforms
- Linux · macOS · Windows
What PHP says it does
Write solid PHP avoiding type juggling traps, array quirks, and common security pitfalls.
Never concatenate SQL — use prepared statements with PDO
npx skills add https://github.com/bighardperson/computer-science-skills-collection --skill phpAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 8 |
|---|---|
| repo stars | ★ 33 |
| Last updated | April 26, 2026 |
| Repository | bighardperson/computer-science-skills-collection ↗ |
What it does
Reference PHP best practices to avoid type-juggling, array, and security pitfalls while coding.
Who is it for?
Writing or reviewing PHP with correct comparisons and safe SQL and output handling
Skip if: Framework-specific Laravel scaffolding beyond core PHP guidance
When should I use this skill?
Writing, reviewing, or refactoring PHP code
What you get
PHP that uses strict comparison, prepared statements, and escaped output.
- PHP coding rules
- security guidance
By the numbers
- 7 topic reference files
- 14 critical rules listed
Files
Quick Reference
| Topic | File |
|---|---|
| Loose typing, ==, ===, type juggling, strict_types | types.md |
| Associative arrays, iteration, array functions | arrays.md |
| Traits, interfaces, visibility, late static binding | oop.md |
| Encoding, interpolation, heredoc, regex | strings.md |
| Exceptions, error handling, @ operator | errors.md |
| SQL injection, XSS, CSRF, input validation | security.md |
| PHP 8+ features, attributes, named args, match | modern.md |
Critical Rules
==coerces types:"0" == falseis true — always use===for strict comparisonin_array($val, $arr)uses loose comparison — passtrueas third param for strictstrpos()returns 0 for match at start — use=== falsenot!strpos()- Never concatenate SQL — use prepared statements with PDO
htmlspecialchars($s, ENT_QUOTES)all output — prevents XSSisset()returns false for null — usearray_key_exists()to check key existsforeach ($arr as &$val)— unset$valafter loop or last ref persistsstatic::late binding vsself::early binding —staticrespects overrides@suppresses errors — avoid, makes debugging impossible- Catch
Throwablefor bothErrorandException— PHP 7+ declare(strict_types=1)per file — enables strict type checkingstrlen()counts bytes — usemb_strlen()for UTF-8 character count- Objects pass by reference-like handle — clone explicitly with
clone $obj array_merge()reindexes numeric keys — use+operator to preserve keys
{
"ownerId": "kn73vp5rarc3b14rc7wjcw8f8580t5d1",
"slug": "php",
"version": "1.0.1",
"publishedAt": 1771103245360
}{
"slug": "php",
"name": "PHP",
"version": "1.0.1",
"installedAt": 1776152390245,
"source": "skillhub"
}Array Traps
array_merge()reindexes — use+operator to preserve numeric keys- Unset doesn't reindex —
unset($arr[1])leaves gap,array_values()to fix foreachby reference —foreach($arr as &$v)keeps ref after loop, unset it$arr[] = xvs$arr[0] = x— first appends, second replacesarray_filter()no callback — removes falsy INCLUDING"0"and0array_mapnull callback — zips arrays together, not what you expectarray_keys()strict — pass third paramtruefor strict comparison- Negative index doesn't wrap —
$arr[-1]is literal key-1, not last element
Error Traps
@suppresses errors — hides problems, never use in production- Exception vs Error —
\Erroris separate hierarchy, catch\Throwable set_error_handler— doesn't catch fatal errorstry/finally— finally runs even on return, but not onexit()- Uncaught exception — fatal error, process dies
error_reporting(0)— still logs to file if configured, not silenttrigger_errorfor warnings — won't throw exception
PHP 8+ Traps
- Named args break rename —
foo(name: $x)breaks if param renamed - Match is exhaustive — no matching arm throws
UnhandledMatchError - Nullsafe
?->— returns null, doesn't short-circuit further ops - Union types null —
int|nullnot same as?intin some contexts - Attributes reflection —
#[Attr]needs ReflectionAttribute to read - Constructor promotion + default —
public int $x = 0in signature str_contains/str_starts_with— PHP 8+, polyfill for older- Enums can't extend — backed enums need type, cases are singletons
OOP Traps
- Late static binding —
self::binds at define time,static::at call time - Abstract class can't instantiate — but CAN have constructor for children
- Trait method conflicts — must resolve with
insteadoforas - Interface constants — can't override in implementing class
- Clone is shallow — nested objects still shared, implement
__clone instanceofwith string —$obj instanceof $classNameworks dynamically- Readonly properties — can only set once, in constructor or declaration
- Constructor promotion —
public function __construct(public $x)declares property
Security Traps
- SQL injection — use prepared statements, NEVER concatenate user input
- XSS —
htmlspecialchars($input, ENT_QUOTES, 'UTF-8')on all output - CSRF — verify token on state-changing requests
- File upload — check MIME type, extension, AND magic bytes
include($userInput)— remote file inclusion, validate path strictlyunserialize()— can execute code, usejson_decode()insteadextract($_POST)— overwrites variables, including$isAdmin- Session fixation —
session_regenerate_id(true)on login - Weak comparison in auth —
"0e123" == "0e456"is true, breaks hash compare
String Traps
- Encoding hell —
strlen()counts bytes not chars,mb_strlen()for UTF-8 strpos()returns 0 —if(strpos(...))fails when found at start, use!== false- Single vs double quotes —
"$var"interpolates,'$var'is literal - Heredoc indentation — closing identifier must not be indented (PHP <7.3)
- Regex delimiters —
/pattern/or#pattern#, forgetting causes error preg_replacewith/e— removed in PHP 7, was code injection vector- Null byte —
"file\0.txt"truncates at null in some functions
Type Traps
==coerces types —"0" == falseis true, always use==="10" == "10.0"— string comparison converts to numbers if both numeric0 == "any"before PHP 8 — legacy code still has this bugin_array()loose — passtrueas third param for strictswitchuses loose comparison — usematchin PHP 8+ for strictempty("0")is true — "0" is falsy, use=== ""orstrlen()- Type declarations coerce —
intparam accepts "123", usestrict_types
Related skills
FAQ
Why use === instead of == in PHP?
== coerces types, so "0" == false is true; === does strict comparison without coercion.
How does the skill prevent SQL injection?
It says never concatenate SQL and to use prepared statements with PDO.