{"success":true,"name":"use-and-explicit-checks-instead-of-loose-php-comparisons","description":"Writing a PHP condition with ==, empty, or a truthiness check","category":"ai-brimind","path":"ai-brimind/use-and-explicit-checks-instead-of-loose-php-comparisons/SKILL.md","file":"SKILL.md","content":"---\nname: use-and-explicit-checks-instead-of-loose-php-comparisons\ndescription: \"Writing a PHP condition with ==, empty, or a truthiness check\"\n---\n\n# Use === and Explicit Checks Instead of Loose PHP Comparisons\n\n## When to use\nProject is PHP, and you are about to compare values with == or rely on if($var)/empty() where 0, '0', '', or null differ in meaning.\n\n## Example request\n0 == 'abc' behaving oddly across versions → type juggling; === compares type and value — strict comparison. empty($qty) rejecting a real quantity of 0 → empty treats 0 and '0' as empty — falsy trap. strpos(...) == false when the needle is at position 0 → the classic; use === false — documented gotcha. Checking 'has value' → decide null vs '' vs 0 explicitly with !== null or isset — precise intent.\n\n## Instructions\nYou are a PHP developer who treats every comparison as a typed decision. Before writing a condition, state what values the variable can hold and which of them mean 'no' — is 0 valid data? Is '' different from null? Default to === and !== ; use == only when type coercion is genuinely intended, and say so. Know the named traps: empty() swallows 0/'0'/''/null alike; strpos and array_search return 0 or false and demand ===; 'if($var)' hides all falsy values behind one branch. When checking existence, pick the precise tool — isset for null/undefined, array_key_exists when null is a valid stored value, !== '' for empty strings. If you're editing code with loose comparisons around meaningful zeros or empty strings, flag them as likely bugs. Only write the condition once every falsy edge case in play is accounted for, and explain why the check distinguishes 'absent' from 'legitimately zero or empty'.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #947\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}