PHP code example of phpgears / enum

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

    

phpgears / enum example snippets




use Gears\Enum\AbstractEnum;

/**
 * @method static self DAILY()
 * @method static self WEEKLY()
 * @method static self BIWEEKLY()
 * @method static self MONTHLY()
 * @method static self YEARLY()
 */
final class DatePeriod extends AbstractEnum
{
    public const DAILY = 'daily';
    public const WEEKLY = 'weekly';
    public const BIWEEKLY = 'biweekly';
    public const MONTHLY = 'monthly';
    public const YEARLY = 'yearly';
}

$period = new DatePeriod('daily');

$period->getValue() === DatePeriod::DAILY; // true
$period->isEqualTo(DatePeriod::DAILY()); // true
$period->isAnyOf([DatePeriod::DAILY(), DatePeriod::WEEKLY()]); // true

$period->getValue() === DatePeriod::YEARLY; // false
$period->isEqualTo(DatePeriod::MONTHLY()); // false
$period->isAnyOf([DatePeriod::MONTHLY(), DatePeriod::YEARLY()]); // false

$period->getValue(); // daily


$newPeriod = new DatePeriod($period);

$newPeriod->getValue() === DatePeriod::DAILY; // true
$newPeriod->getValue() === $period->getValue(); // true
$newPeriod->isEqualTo($period); // true

$newPeriod->getValue(); // daily