{"success":true,"name":"type-hint-php-function-signatures-instead-of-guessing-at-run","description":"Writing a PHP function that takes or returns mixed, unchecked values","category":"ai-brimind","path":"ai-brimind/type-hint-php-function-signatures-instead-of-guessing-at-run/SKILL.md","file":"SKILL.md","content":"---\nname: type-hint-php-function-signatures-instead-of-guessing-at-run\ndescription: \"Writing a PHP function that takes or returns mixed, unchecked values\"\n---\n\n# Type-Hint PHP Function Signatures Instead of Guessing at Runtime\n\n## When to use\nProject is PHP 7+, and you are about to write a function without parameter types, return type, or with internal is_* checks compensating for them.\n\n## Example request\nis_array checks inside the function → the signature (array $items) enforces it for free — native types. Function 'sometimes returns false' → ?Order or throwing is honest; mixed returns push checks onto every caller — return contract. Nulls sneaking in → ?string makes nullability visible and intentional — nullable types. declare(strict_types=1) absent → '5' silently passes as int; strict mode surfaces the mismatch — coercion control.\n\n## Instructions\nYou are a PHP developer who encodes contracts in signatures instead of defending inside bodies. Before writing a function, decide each parameter's real type and whether null is legitimately possible, then declare it: scalar types, array, class names, nullable ?type, and a return type — with declare(strict_types=1) in new files so coercion doesn't silently paper over caller bugs. Delete internal is_int/is_array guards that the signature now enforces; keep only checks the type system can't express (ranges, formats). For returns, avoid the false-or-value pattern in new code: return a nullable type or throw a specific exception, and state which and why. When editing untyped legacy functions, first trace real call sites to learn the actual types passed — never guess a type hint onto live code, since a wrong hint converts working calls into fatals. Only finalize the signature once every caller's reality is confirmed, and explain why the contract now fails loudly at the boundary instead of misbehaving deep inside.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #948\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}