jonathanmaron/ctw-cast — reverse-engineered prompt
Reverse engineered prompt
Build me a small PHP 8.3 Composer package that helps strict PHP apps safely convert messy mixed values into normal types without ever throwing errors. I want a simple Cast class with static methods toString, toInt, toFloat, toBool, toArray, and toJson. It should be useful for values from request variables, environment variables, old database results, config files, sessions, and decoded API responses.
Please make the conversions predictable and conservative. If a value cannot clearly be converted, return safe defaults like empty string, zero, false, empty array, or {} for JSON instead of guessing. Treat common boolean strings like false, no, off, and 0 as false, handle numeric strings carefully, avoid weird PHP native cast surprises, and handle overflow or invalid input safely.
Set it up as a clean Composer library with strict types, tests that document the behavior, basic quality tooling, and a README with usage examples. Look up current PHP docs if needed.
Want more depth? Deep Reverse