PHP code example of martijnvdb / type-vault
1. Go to this page and download the library: Download martijnvdb/type-vault 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/ */
martijnvdb / type-vault example snippets
use Martijnvdb\TypeVault\Types\Email;
$email = new Email("[email protected]");
echo $email->value; // '[email protected]'
// Update the value with another valid email
$email->value = "[email protected]";
echo $email->value; // '[email protected]'
use Martijnvdb\TypeVault\DTOs\TypeOptionsDTO;
use Martijnvdb\TypeVault\Errors\ImmutableValueError;
use Martijnvdb\TypeVault\Errors\TypeVaultValidationError;
use Martijnvdb\TypeVault\Types\Email;
$immutable = Email::immutable("[email protected]");
// Or:
$immutable = new Email("[email protected]", new TypeOptionsDTO(immutable: true));
echo $immutable->value; // '[email protected]'
try {
$immutable->value = "[email protected]"; // ❌
} catch (ImmutableValueError $error) {
// Specific immutable mutation error
} catch (TypeVaultValidationError $error) {
// Fallback for any Type Vault validation error
}