alphred icon indicating copy to clipboard operation
alphred copied to clipboard

Bug in tutorial

Open ghost opened this issue 8 years ago • 1 comments

Damn, Shawn! You've done a hell of a big job with this utility library!

I haven't used the library yet, but I am 100% sure this line from the tutorial is bugged though:

$repos = $workflow->filter( $repos, $query, 'name', [ 'match_type' => MATCH_STARTSWITH && MATCH_ATOM && MATCH_SUBSTRING ] );

The && operator is the comparison operator. The result of the line above is to say: "If match_startswith evaluates to true, and match_atom evaluates to true, and match_substring evaluates to true, then set 'match_type' to TRUE, otherwise FALSE". So it sets match_type to a boolean yes/no value.

The similar looking & would instead give you the binary AND operator, which is not what you want EITHER. That one only merges flags wherever all of their bits match.

What you want is the | operator for binary OR, demonstrated here:

$one = 2;
$two = 16;
echo ( $one | $two ); // 18

Just beware: Your flags must all be single-bit values. So binary values: 1, 2, 4, 8, 16, 32, etc. Each of those numbers only set a single bit to 1 in their bitmasks.

ghost avatar Feb 21 '17 19:02 ghost

You had me at bit.

Definitely a sloppy error on my part. I'll update it shortly.

shawnrice avatar Feb 22 '17 15:02 shawnrice