Last active
December 16, 2015 14:39
-
-
Save dave-jay/5450379 to your computer and use it in GitHub Desktop.
Escape in php to stop throwing 'undefined index/var' notice while using var directly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function _e(&$a,$return=NULL){ | |
return isset($a) ? $a : $return; | |
} | |
// usages | |
# scenario #1 | |
$field = _e($_GET['field']); | |
# if field is not set, it will be set to null | |
# scenario #2 | |
$field = _e($_GET['field'],'id); | |
# if field is not set, it will set to 'id' | |
# saving two lines of if code :) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
_e function expects first arg as 'reference', so it wont throw notice :)