Basically I need to create a string with $_GET['param'], something like:
$myString = $_GET['param'] . 'abc';
When $_GET['param'] isn’t isset i am perfectly fine with $myString being just ='abc'
-
So I can do something like this:
$myString = @$_GET['param'] . 'abc'; -
Or use the standard way with isset:
if (!isset($_GET['param'])) $_GET['param'] = ''; $myString = $_GET['param'] . 'abc';
In this case using the @ suppresser is considering such a bad pratice?
The most elegant thing IMHO would be to wrap that in a nice getter function, something like:
yes123 note:
As dvir said having a getter function for input variables in your framework can be handy. But this
_getParamsuffers of this problem:Let’s see we make a typo in our code, we want to access
$_GET['param']and istead of it we type:Our code will work without generting any problems and we will have hard time finding the error.
So I thought we could modify the function presented to something like:
This ensures that when we typo it with
_get('parm')we will get a notice throwed normally. But when we use it with 2 param we get out default value: