David Coallier has posted a nice overview of what SPL Types are in PHP and a brief example of hos they can be used. SPL_Types are a way to make PHP strongly typed (no adapting variables) to help make a PHP application “more correct” by forcing the variable’s type to stay the same. His example shows the creation of a few variables with these new methods and how they can be used, both correctly and incorrectly.

About php: I got karma to SPL_Types and added a new SplFloat() object, a few warning typos and more “flexible” strict modes for different types.

A bit about Spl_Types:

Q:What is SPL Types ?

A: It’s a way to make PHP Strongly typed.

Q: Why would you use that ?

A: To strong type your code! Meaning, enforcing a type of variable

<?php
$int = new SplInt(3);
$float = new Float(3.1412);
try {
    $int = 'string';
} catch (UnexpectedValueException $e) {
    echo $e->getMessage();
}
try {
    $float = 'More string values';
} catch (UnexpectedValueException $f) {
    echo $f->getMessage();
}
$float = 4; // This works btw ;-)  it becomes (float)4
// Etc etc etc...
echo $int;
echo $float;
echo '-' . $bool . '-';
// I will post a more detailed tutorial about it as soon as a few plans have been sorted,
// until then, you can use it if you feel like it :-) 
// Imagine ...
$id = (int)$_GET['id'];
// And later on by inadvertance, some other developer decides to make that into something naughty like
// like $id = $_GET['id'] elsewhere, it becomes a security threat because if you initially casted to (int), it doesn't
// make it strict so one could overwrite it, whereas with SplInt($_GET['id']); you will not be able to overwrite it without
// throwing an exeception (to something else than an int of course. If that $_GET['id'] has been changed to
// something like ' or ''=', it will throw an exception, etc etc.
// I am sure some of you will make something usefull out of that..
?>

Enjoy!