PHP code example of ornament / bitflag
1. Go to this page and download the library: Download ornament/bitflag library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ornament / bitflag example snippets
use Ornament\Core;
use Ornament\Bitflag\{ Bitflag, Options };
enum Status : int
{
case on = 1;
case initialized = 2;
}
class Model
{
use Core\Model;
#[Options(Status::class)]
public Bitflag $status;
}
$model = Model::fromIterable(['status' => 3]);
// Now this works, assuming `$model` is the instance:
var_dump($model->status->on); // true in this example, since 3 & 1 = 1
$model->status->on = true; // bit 1 is now on (status |= 1)
$model->status->on = false; // bit 1 is now off (status &= ~1)
var_dump($model->status->initialized); // true, since 2 & 2 = 2
echo Status::on->value; // 1