PHP code example of try-again-later / multi-backed-enum

1. Go to this page and download the library: Download try-again-later/multi-backed-enum 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/ */

    

try-again-later / multi-backed-enum example snippets


use TryAgainLater\MultiBackedEnum\{MultiBackedEnum, Values, MakeMultiBacked};

#[MultiBackedEnum]
enum Status
{
  #[Values('on', 'true', 'yes')]
  case ON;

  #[Values('off', 'false', 'no', 'null')]
  case OFF;

  use MakeMultiBacked;
}

// Status::ON
$status = Status::tryFrom('true');

// Throws a ValueError
$status = Status::from('some bad value');

// 'off'
$stringStatus = Status::OFF->value();

// ['on', 'true', 'yes']
$stringStatuses = Status::ON->allValues();