php-conventions
PHP Conventions
These are non-negotiable personal conventions unless explicitly overridden by the user.
Language & Syntax
-
Strict types — Every PHP file must declare
declare(strict_types=1);at the top. If it is an existing file or extracting legacy code (which may depend on type-juggling) into a new file, you do not need to add it, but mention it to the user. -
Prefer explicit falsy checks — Use the narrowest comparison that matches the real condition, such as
=== null,=== '', or=== 0, instead of broad checks likeif (! $someValue). Negation is fine when the value is genuinelybool(for example,if (! $isEnabled)). This avoids surprising type coercion and makes intent clearer to humans and tools. Though usingempty()is not preferred, it is better than writing methods like this:// Unnecessary code, don't do this: public function isNonEmptyEmail(?string $email): bool { return $email !== null && $email !== ''; }