note 85156 modified in language.operators.bitwise by felipe

From: Date: Tue, 19 Aug 2008 01:43:00 +0000
Subject: note 85156 modified in language.operators.bitwise by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-143616@lists.php.net to get a copy of this message
Here is a usefull class to work with flags: <?php class flags { function has_flag($flags, $flag_check) { if (($flags & $flag_check) == $flag_check) { return true; } return false; } function add_flag($flags, $flag_check) { // already have the flag, so return it as it is if ($this->has_flag($flags, $flag_check)) { return $flags; } return $flags ^ $flag_check; } function del_flag($flags, $flag_check) { // already have not the flag, so return it as it is if (!$this->has_flag($flags, $flag_check)) { return $flags; } return $flags ^ $flag_check; } } ?> --was-- Here is a usefull class to work with flags: class flags { function has_flag($flags, $flag_check) { if (($flags & $flag_check) == $flag_check) { return true; } return false; } function add_flag($flags, $flag_check) { // already have the flag, so return it as it is if ($this->has_flag($flags, $flag_check)) { return $flags; } return $flags ^ $flag_check; } function del_flag($flags, $flag_check) { // already have not the flag, so return it as it is if (!$this->has_flag($flags, $flag_check)) { return $flags; } return $flags ^ $flag_check; } } http://php.net/manual/en/language.operators.bitwise.php

« previous php.notes (#143616) next »