PHP code example of vcn / enum

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

    

vcn / enum example snippets




use Vcn\Lib\Enum;

/**
 * @method static Fruit APPLE()
 * @method static Fruit BANANA()
 */
class Fruit extends Enum
{
    protected const APPLE  = 0;
    protected const BANANA = 0;
}

Fruit::APPLE()->equals(Fruit::BANANA()); // false
Fruit::APPLE()->equals(Fruit::APPLE()); // true

Fruit::APPLE()
    ->when(Fruit::APPLE(), 'apple')
    ->when(Fruit::BANANA(), 'banana')
    ->get(); // 'apple'


 
final class Fruit extends Enum {}



final class Fruit extends Enum {
    protected const APPLE  = 0;
    protected const BANANA = 0;
}



/**
 * @method static Fruit APPLE()
 * @method static Fruit BANANA()
 */
final class Fruit extends Enum {
    protected const APPLE  = 0;
    protected const BANANA = 0;
}



$banana = Fruit::APPLE();
$apple  = Fruit::BANANA();



Fruit::APPLE()->equals(Fruit::BANANA()); // false
Fruit::APPLE()->equals(Fruit::APPLE()); // true



Fruit::APPLE()
    ->when(Fruit::APPLE(), 'apple')
    ->when(Fruit::BANANA(), 'banana')
    ->get(); // 'apple'



Fruit::APPLE()->getName(); // 'APPLE'

Fruit::byName('APPLE'); // Fruit::APPLE()



Fruit::isExhaustive([Fruit::APPLE()]); // false

Fruit::isExhaustive([
    Fruit::APPLE(),
    Fruit::BANANA()
]); // true