(PECL spl_types >= 0.1.0)
SplInt::__construct — Construit un objet de type integer
Ce constructeur est utilisé pour attribuer et garantir le type de l'objet "Integer".
Le paramètre input prend un integer et produit une exception UnexpectedValueException si autre donnée lui est passée.
Aucune valeur n'est retournée.
Exemple #1 Exemple avec SplInt::__construct()
<?php
$int = new SplInt(94);
try {
$int = 'Essayez de transtyper une chaîne pour le fun';
} catch (UnexpectedValueException $uve) {
echo $uve->getMessage() . PHP_EOL;
}
var_dump($int);
echo $int; // Affiche 94
?>
L'exemple ci-dessus va afficher :
Value not an integer object(SplInt)#1 (1) { ["__default"]=> int(94) } 94