Download the PHP package zakirullin/mess without Composer
On this page you can find all versions of the php package zakirullin/mess. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zakirullin/mess
More information about zakirullin/mess
Files in zakirullin/mess
Package mess
Short Description Convenient array-related routine & better type casting
License MIT
Homepage https://github.com/zakirullin/mess
Informations about the package mess
Mess
We face a few problems in our PHP projects
- Illogical type casting (
PHP
's native implementation is way too "smart") - Pointless casts like
array => float
are allowed - Boilerplate code to work with arrays (check if
isset()
, throw an exception, cast the type, etc.)
Consider an example:
Way too verbose. Any ideas?
You can mess with API responses/configs/whatever:
Generics support (Psalm compatible)
getListOfString()
getListOfInt()
getArrayOfStringToString()
getArrayOfStringToBool()
- etc.
Installation
Dealing with mess
As you might notice, type casting is performed while using (find|get)As*
methods.
Having trouble grasping get*()
/find*()
? Check out brilliant Ocramius's slides.
Type casting with Mess is rather predictable
Fairly simple, isn't it? Let us fail fast!
Why one needs THAT naive type casting?
Let's imagine a library that is configured this way:
Client-side code:
No matter if that's a misuse, or a result of major update: The system will continue to work.
And that's the worst thing about it. It will continue to work, though, not in a way it was supposed to work.
PHP
is trying to do its best to let it work at least somehow.
The library comes in handy in a variety of scenarios 🚀
- Deserialized data
- Request
body
/query
API
response- Config
- etc.