I am tired of using code like:
$blog = isset($_GET['blog']) ? $_GET['blog'] : 'default';
but I can't use:
$blog = $_GET['blog'] || 'default';
Is there any way to do this without using isset()
?
I am tired of using code like:
$blog = isset($_GET['blog']) ? $_GET['blog'] : 'default';
but I can't use:
$blog = $_GET['blog'] || 'default';
Is there any way to do this without using isset()
?
You have to wait for the next version of PHP to get the coalesce operator
Write a helper function.
Usage:
You can just write a custom helper:
Alternatively, you have the filter extension, e.g.:
It's not noticeably shorter but allows further validation and sanitisation (and it's also trivial to wrap in a custom function).
No there is no shorter way than that. You can create a class that handles the $_POST and $_GET variables and just user it whenever you call the blog.
Example:
$blog = Input::put("blog");
The input class will have a static method which will determine when input is either have a $_POST and $_GET or a null value.