Skip to content

Instantly share code, notes, and snippets.

@marcojetson
Created June 21, 2016 11:51
Show Gist options
  • Save marcojetson/c415b5a7e4c2162e9eb06ab31216da55 to your computer and use it in GitHub Desktop.
Save marcojetson/c415b5a7e4c2162e9eb06ab31216da55 to your computer and use it in GitHub Desktop.
Flag trait
<?php
trait FlagTrait
{
/** @var int */
private $flags = 0;
/**
* @param int $flag
* @return bool
*/
public function flagged($flag)
{
return (bool)($this->flags & pow($flag, 2));
}
/**
* @param int $flag
*/
public function flag($flag)
{
$this->flags |= pow($flag, 2);
}
/**
* @param int $flag
*/
public function unflag($flag)
{
$this->flags &= ~pow($flag, 2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment