PHP code example of javalikeenum / enum

1. Go to this page and download the library: Download javalikeenum/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/ */

    

javalikeenum / enum example snippets


use JavaLikeEnum\Enum;

final class ItemType{
  use Enum;

  const FOOD = 1;
  const SERVICE = 2;
  const DRINK = 3;
}

assert(ItemType::FOOD() === ItemType::FOOD());

try {
  $a = clone ItemType::FOOD();
} catch (LogicException $e) {
  assert(true);
}

assert(ItemType::values() === [ItemType::FOOD(), ItemType::SERVICE(), ItemType::DRINK()]);
assert('1' === (string) ItemType::FOOD());