Because, passing by reference means you are passing a reference to the memory location used by whatever variable you supply. You are not supplying a variable, you are supplying a value (NULL)
The value of these expression are null and 5, not $var and $var2
$var = null;
$var2 = 5;
And passing values by reference makes no sense. You can only pass variables by reference.
$stmt = $db->prepare('SELECT * FROM table WHERE field = :message');
/* Binding as a parameter means binding to the variable's reference, i.e. its memory location.
* Therefor you must have defined the variable first
*/
$message;
$stmt->bindParam(':message', $message, PDO::PARAM_STR);
$message = 'I will be selected';
$stmt->execute();
$message = 'Now it is my turn';
$mysql_query->execute();
function callingCodeVariableUpdated(&$out) { $out = 'Changed again'; }
callingCodeVariableUpdated($message);
$mysql_query->execute();
While this would make no sense at all
callingCodeVariableUpdated(5);
which would imply
5 = 'Changed again';
Also you do not have to bind an empty string as null. While there is a difference between the empty string and null
INSERT INTO a(id, txt)
VALUES
(1, ''),
(2, null);
-- finds: 1, ''
SELECT *
FROM a
WHERE txt = '';
-- finds: 2, null
SELECT *
FROM a
WHERE txt IS NULL;
Is there really a point to not simply bind to $message_mailbox as PARAM_STR?