(no title)
Spykk | 13 years ago
$id = 1;
$dbh = new PDO($connectionString, $user, $password);
$sql = ' SELECT column';
$sql .= ' FROM table';
$sql .= ' WHERE id = :id';
$stmt = $dbh->prepare($sql);
$stmt->bindParam(':id', $id);
if($stmt->execute()) {
// Do stuff
}
//This echos ID: 1
echo "ID: $id";
if($id === 1) {
echo 'This should be true, we set $id = 1 at the top.';
} else {
echo 'Instead we get here because PDO casually changed our variable into a string and "1" != 1.';
die('in a fire dynamic typing.');
}
ScottBurson|13 years ago
You're confusing dynamic typing with weak typing. A language can be dynamically typed (types are checked at runtime) without doing things like automatically converting integers to strings, integers and strings to booleans, etc. etc.
Conversely, a language can be statically typed and still do some of those conversions.