3 ms·
For "functions that return false", use thecodingmachine/safe which wraps those nasty builtins with ones that throw exceptions. PHP's gotten a lot better lately
by chuckadams 3y ago
For "functions that return false", use thecodingmachine/safe which wraps those nasty builtins with ones that throw exceptions. PHP's gotten a lot better lately, but it's always going to need library fixes like that for its awful legacy builtins.
- alfredbez 3y agoI like this library and promote that wherever I can, but the safe library was even mentioned in the post: > I love the smell of false in the morning, but despite that I do wish that all PHP’s built-in functions threw exceptions. We have the famous safe library which does just that! But if you’re like me then you don’t like coupling huge amounts of code in perpetuity to an external library.
- chuckadams 3y agoAh, I'd completely missed that. As for depending on an external library ... get used to it. Writing PHP without any external deps is strictly for one-off scripts -- and rarely even then.
- user3939382 3y agoI just wrap the ones I actually need that for and put them in traits (sometimes multiple related per trait). So it's internal, small footprint, and really needs 0 maintenance. This is also good for e.g. json_* when you want to provide app-wide defaults.