PHP code example of webservco / constant-value-class

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

    

webservco / constant-value-class example snippets


class Shipment
{
    public function send(Type $type): bool
    {
        // ...
    }
}
$shipment = new Shipment();
$shipment->send(Type::import());

// or
$type = 2; // request parameter, user input, etc
$shipment->send(Type::fromValue($type));

// get value (exact type) (eg. for form select)
echo Type::import()->value(); // outputs "1"

// get string representation of value
echo Type::import(); // outputs "1"

// comparison
$import = Type::fromValue(2);
if (Type::import() === $import) {
    // === works as long as the object is created in the current script run,
    // not for example created elsewhere and stored serialized in session.
}