On his Medium.com blog Liam Hammett has written up a tutorial explaining the functionality and use of bitmask constant arguments in PHP.
PHP has a handful of core functions that can accept boolean arguments in the form of constants that have a binary value.
These can be combined together in a single function argument, essentially passing multiple boolean flags in a very compact manner. They work a bit differently to how most people implement options in their userland functions, so let’s take a look at how they work.
He starts off by talking about how the PHP core language makes use of them in certain functions with an example of the
JSON_THROW_ON_ERROR constant for use with json_encode (both as a single option and multiple using a bitwise operator). He then gets into the "code behind the code" and talk about how they work for both "OR" and "AND" types. He ends the post with an example putting all of this knowledge to use in an
if that detects if a bit exists in the inputted constant list.