So I was playing around with some session variables today and was coming across an error.
I was using
Code: Select all
<?php
$_SESSION['id'] = $row['id'];
echo $_SESSION['id']; // returned: 1
$id = $_SESSION['id'];
if (is_int($id)) {
echo $id.' is an integer';
} else {
echo $id.' is not an integer';
}
?>
This code was always returning false and saying it wasn't an integer. So then I tried the following, which properly worked.
Code: Select all
$_SESSION['id'] = $row['id'];
echo $_SESSION['id']; // returned: 1
$id = $_SESSION['id'];
if ((int)$id == $id) {
echo $id.' is an integer';
} else {
echo $id.' is not an integer';
}
?>
Is there a reason why the is_int() function wasn't working as expected? Is the $_SESSION returning this as some sort of string with the way I was doing it or something? My guess is yes, but why does just the simple echo of the $_SESSION return an integer then?