PHP code example of klamius / php-enum

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

    

klamius / php-enum example snippets


use Klamius\Enum\Enum;

/**
 * GenderEnum enum
 */
class Gender extends Enum
{
    const MALE = 'male';
    const FEMALE = 'female';
}

class User
{
    /**
     * @var Gender
     */
    private $gender;
    
    function setGender(Gender $gender)
    {
        $this->gender = $gender;
    }
}

$gender = new Gender(Gender::MALE);
$user->setGender($gender);

//or
echo $gender;

composer