PHP code example of joaomfrebelo / enum

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

    

joaomfrebelo / enum example snippets


/**
 * The enumeration class
 */
final class MyExample extends \Rebelo\Enum\AEnum
{
    const EXAMPLE_1 = 1;
    const EXAMPLE_2 = 2;

    public function __construct($value)
    {
        parent::__construct($value);
    }
}

class Foo
{
    /**
     *
     * This method will only acept values of MyExample enumeration class
     *
     * @param MyExample $myExample
     */
    public function myMethod(MyExample $myExample)
    {
        $value = $myExample->get();
        // do stuff
    }
}

$foo = new foo();
$foo->myMethod(new MyExample(MyExample::EXAMPLE_1));