One of the most frustrating parts of using Hack is accessing user-provided data through the request based
$_POST super-globals. The problem being two-fold:
- In partial mode, these aren’t typed. This means Hack assumes you know what you’re doing with the values, which can be bad.
- In strict mode, the super globals aren’t available and result in undefined variable errors in the type checker.
That’s where my new package comes in.
There are methods to check that a value is provided and to get values out as any of:
As most of the data coming in is a string (due to how PHP handles HTTP parameters), loss-less conversions happen. If the conversion would result in a loss of data, then it doesn’t happen and either
null is returned or an exception is thrown.
Once installed, the package provides wrappers for the
$_SERVER super globals.
Usage information and examples are included in the documentation.
Give it a try and let me know what you think, either as comments on this post or by opening issues on the repo.