Does PDO bindParam allow not existent variables?
error-handling, mysql, pdo, php
Solution
You don't see the notice because the arguments of bindParam are passed as reference.
function test(&$var) {
// var may also be undefined
var_dump($var);
}
test($undef);
This don't throw any error. Doc: What References Do
Problem
As during development I set `error_reporting(-1);` so I was sure that every syntax error will be shown by PHP. It is, for example ``` echo $ttt; ``` of course it gives ``` Notice: Undefined variable: ttt in ... ``` In this piece of code (a part of some class representing a row in mysql table): ``` public function delete(){ // ... $sth=$dbh->prepare('DELETE FROM tobjects WHERE IdObject=:id'); $sth->bindParam(':id',$this->fid,PDO::PARAM_INT); $sth->execute(); ``` I mistyped what is now `$this->fid` and the deletion did not occur, no error was even to be noticed, and I spent long time to find it. The `$dbh` is set elsewhere as: ``` $dbh=new PDO("mysql:host=XXXX;port=XXXX;dbname=XXXX",$db_user, $db_password,array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'')); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); ``` Am I doing something wrong or how is it possible that no error was given?