PHP
PHP 8+ is a dynamic scripting language optimized for server-side rendering, APIs, and CLI tooling.
Keywords & Syntax
- Keywords: abstract, array, as, break, callable, case, catch, class, clone, const, continue, declare, default, die, do, echo, else, elseif, empty, enddeclare, endfor, endforeach, endif, endswitch, endwhile, enum, eval, exit, extends, final, finally, fn, for, foreach, function, global, goto, if, implements, include, include_once, instanceof, insteadof, interface, isset, list, match, namespace, new, print, private, protected, public, readonly, require, require_once, return, static, switch, throw, trait, try, unset, use, var, while, yield.
- Variables always start with $. Types include scalar, array, object, callable, iterable.
- Attributes (`#[ORM\Entity]`) offer metadata similar to annotations.
- Named arguments and union types (string|int) bring clarity.
Common Functions & Operators
- String helpers: strlen, strpos, substr, sprintf, preg_match, preg_replace.
- Array helpers: array_map, array_filter, array_reduce, array_merge, array_column.
- DateTime, Intl, and BCMath extensions for robust domains.
- Operators mirror C-style languages plus null coalescing (??) and spaceship (<=>).
Runtime & Ecosystem
- Runs under FPM, Apache mod_php, Swoole, RoadRunner, ReactPHP.
- Composer handles autoloading and dependency graphs via PSR standards.
- Frameworks: Laravel, Symfony, Slim, CodeIgniter, WordPress core APIs.
- PSR interfaces (PSR-7, PSR-15, PSR-18) unify HTTP middleware.
Performance & Safety
- OPcache stores bytecode in shared memory.
- JIT (PHP 8) accelerates math-heavy workloads.
- Static analysis: Psalm, PHPStan, Phan catch issues pre-runtime.
- Security basics: escape output, use parameterized queries, rotate session IDs.
Best Practices
- Adhere to PSR-1/PSR-12 coding standards.
- Leverage dependency injection containers (Symfony, Laravel service providers).
- Prefer immutable value objects for domain data.
- Write tests with Pest or PHPUnit and run via GitHub Actions.