Hi
I have searched through the manual but couldn't find any reference to this behaviour.
If you accidentally try to use a session variable in a PDO PreparedStatement using bindParam() - say because you mistyped it or because you mistakenly tried to access a session variable you had not set, then that new variable is added to the session with a NULL value.
So your session might have been started elsewhere with this:
if you then unthinkingly later do this (where person_type has not been explicitly set)PHP Code:$_SESSION['person_name'] = "Dick";
your session will magically contain:PHP Code:$stmt = $PDO->prepare("insert into people ? , ? ") ;
$stmt->bindParam( 1 , $_SESSION['person_name'] );
$stmt->bindParam( 2 , $_SESSION['person_type'] );
Which is something I wasn't expecting, and fooled me for a while (not hard to do, I admit).PHP Code:$_SESSION['person_name'] = "Dick";
$_SESSION['person_type'] = &NULL;
IIS6, PHP5.2.5, win2k, error_reporting (E_ALL) indicates nothing wrong.
Whereas if you simply do this:
It DOES throw a Notice, and does not go on to create the session variable.PHP Code:$t = $_SESSION['person_type'] ;
I don't know about for you, but this behaviour may create problems somewhere else, say if you are inserting session vars into a table using some kind of sql query generator.
Or would $_SESSION['person_type'] = &NULL; never be detectable?







Bookmarks