PHP code example of divengine / enum

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

    

divengine / enum example snippets




ivengine\enum;

abstract class Temperature extends enum {}
class HOT extends Temperature {}
class COLD extends Temperature {}

function advise(Temperature $t): string
{
    if ($t instanceof HOT) {
        return 'Drink water';
    }
    return 'Wear a coat';
}

echo advise(new HOT());



class HOT extends Temperature
{
    public $value = 'hot';
}

$hot = new HOT();
echo $hot->getValue(); // hot
echo (string) $hot;    // hot