Omitting function arguments in PHP -
i have function saves every user log looks
<?php function create_log($action=null, $outcome, $message) { require 'dbc.php'; include 'get_ip.php'; $ip = get_ip_address(); $datetime = date('m-d-y h:i:s a', time()); $query = "insert tbllogs (logorigin, logaction, loguser, logdate, logoutcome, logmessage) values (:origin, :action, :user, :dt, :outcome, :message)"; $stmt = $dbc->prepare($query); $stmt->bindparam(':origin', $ip); $stmt->bindparam(':action', $action); $stmt->bindparam(':user', $_session['id']); $stmt->bindparam(':dt', $datetime); $stmt->bindparam(':outcome', $outcome); $stmt->bindparam(':message', $message); $stmt->execute(); }
and when call doing this:
create_log('log in', 'failed', '');
my problem is, $message parameter used whenever need only. should call create_log('log in', 'failed', '');
or can call this? create_log('log in', 'failed');
? if so, how?
you specify default values parameters:
function create_log($action = '', $outcome = '', $message = '')
this way, if call create_log
without 1 of parameters, assigned value in function's definition (''
parameters in above example).
Comments
Post a Comment