- Prefer simple solutions over clever ones.
- Write code that is clear and self-explanatory.
- Build with the long term in mind.
- PHP
- Tailwind CSS (if serving frontend)
- Always add
declare(strict_types=1);as the first statement in every PHP file. - Always use Composer for dependency management and PSR-4 autoloading. Never manually
requireorincludeclass files. Never runcomposer updatein production — usecomposer installwhich respectscomposer.lock. - Always place every class in a namespace that maps to its file path per PSR-4. Never define classes in the global namespace.
- Always use PDO with prepared statements and parameter binding for all database queries. Never interpolate or concatenate variables into SQL strings. Set
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTIONandPDO::ATTR_EMULATE_PREPARES => false. - Always use
password_hash()withPASSWORD_DEFAULTfor storing passwords andpassword_verify()for checking them. Never usemd5(),sha1(), or any generic hashing function for passwords. - Always use exceptions for error signaling, not return codes. Catch specific exception types rather than bare
\Exception. Never suppress errors with the@operator. - Always inject dependencies through constructor parameters with type declarations. Never instantiate collaborators inside a class with
new(except for value objects/DTOs). Never pass the DI container itself into application classes. - Always validate and sanitize all external input. Use
filter_var()with specific filter constants for validation. Always usehtmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8')when outputting user-supplied values into HTML. - Always configure sessions securely:
use_strict_mode,use_only_cookies,cookie_httponly,cookie_secure, andcookie_samesite = "Lax". Always callsession_regenerate_id(true)after any privilege change. - Always declare parameter types, return types, and property types on every method and property. Use
enuminstead of class constants for fixed sets of values. - Keep the public document root in a
public/directory containing only the front controller and static assets. Never place PHP source files,.envfiles, orcomposer.jsoninside the web-accessible document root. - Use PSR-3
LoggerInterfacefor logging. Never useerror_log()orechofor application logging.
After making changes, always run the following checks and fix any issues before considering work complete:
- Lint:
composer lint(PHP CS Fixer or PHP_CodeSniffer) - Static analysis:
composer analyse(PHPStan) - Tests:
composer test(PHPUnit)