SplInt
PHP Manual

SplInt::__construct

(PECL spl_types >= 0.1.0)

SplInt::__constructConstruit un objet de type integer

Description

SplInt::__construct ( integer $input )

Ce constructeur est utilisé pour attribuer et garantir le type de l'objet "Integer".

Liste de paramètres

input

Le paramètre input prend un integer et produit une exception UnexpectedValueException si autre donnée lui est passée.

Valeurs de retour

Aucune valeur n'est retournée.

Exemples

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


SplInt
PHP Manual