php - Ignore notices in ternary conditions -
i wondering if it's possible selective in context undefined variable can ignored. ternary conditions, idea can set default value undefined setting, so:
$date = $_post['date'] ?: date();
and use this, had ignore e_notice
errors.
however, don't idea of undefined variables being ignored, , accidentally using undefined variables go unnoticed. wondering if there possibility of middle ground situation?
just clarify, aware of non-ternary solutions, such
$date = (isset($_post['date'])) ? $_post['date'] : date(); // or $date = date(); if(isset($_post['date'])) { $date = $_post['date']; }
but i'm trying ask is, there way reap benefits of shorthand ternary conditions, while still avoiding supressing notices undefined variables.
just prepend @
:
$date = @$_post['date'] ?: date('y-m-d'); ^
anyway, suggest verify isset
instead:
$date = isset($_post['date']) ? $_post['date'] : date('y-m-d');
Comments
Post a Comment