How to implement a bitmask in php?

前端 未结 3 903
遇见更好的自我
遇见更好的自我 2020-12-04 07:15

I\'m not sure if bitmask is the correct term. Let me explain:

In php, the error_reporting function can be called multiple ways:

// Repor         


        
3条回答
  •  醉梦人生
    2020-12-04 07:48

    The others have offered good suggestions, but these days it's much more common to pass in associative arrays instead of bitmasks. It's much more readable and allows you to pass in other variables other than just true/false values. Something like this:

    myFunction(['includeHidden' => true, 'fileExts' => false, 'string' => 'Xyz']);
    
    function myFunction($options) {
        // Set the default options
        $options += [
            'includeHidden' => false,
            'fileExts' => true,
            'string' => 'Abc',
        ];
    
        if ($options['includeHidden']) {
            ...
        }
        ...
    }
    

提交回复
热议问题