Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Liam Hammett:
Bitmask Constant Arguments in PHP
Sep 12, 2018 @ 10:32:33

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.

tagged: bitmask constant argument tutorial example introduction

Link: https://medium.com/@liamhammett/bitmask-constant-arguments-in-php-cf32bf35c73

PHPBuilder.com:
BitMasks: Emulate Unix Permissions in PHP (Quickly)
Aug 09, 2006 @ 16:01:53

Permissions in Unix-based systems have become one of the standard models for development all over the world. They're simple to learn and use while being extremely powerful at the same time. In this new article (as contributed by Eric Potvin) from PHPBuilder.com today, they bring this power to the realm of PHP with bitmasks.

Bitmasking is a very useful method to emulate Unix-style file permissions (read/write/execute for example). What's nice about a PHP implementation is that you can configure your own bitmasks and use them for any kind of permissions in your scripts and applications. The implementation is relatively simple as well.

They start by defining a few of the permission levels (add/delete/denied) in PHP constants before showing the bitMask() function you can use to check a user's permissions. They also include some simple pseudo-code to show how it's used. For more information, check out the complete article here.

tagged: bitmask unix permissions tutorial define constants bitmask unix permissions tutorial define constants

Link:

PHPBuilder.com:
BitMasks: Emulate Unix Permissions in PHP (Quickly)
Aug 09, 2006 @ 16:01:53

Permissions in Unix-based systems have become one of the standard models for development all over the world. They're simple to learn and use while being extremely powerful at the same time. In this new article (as contributed by Eric Potvin) from PHPBuilder.com today, they bring this power to the realm of PHP with bitmasks.

Bitmasking is a very useful method to emulate Unix-style file permissions (read/write/execute for example). What's nice about a PHP implementation is that you can configure your own bitmasks and use them for any kind of permissions in your scripts and applications. The implementation is relatively simple as well.

They start by defining a few of the permission levels (add/delete/denied) in PHP constants before showing the bitMask() function you can use to check a user's permissions. They also include some simple pseudo-code to show how it's used. For more information, check out the complete article here.

tagged: bitmask unix permissions tutorial define constants bitmask unix permissions tutorial define constants

Link: