Saturday 25 March 2017

php 5.3 - Using PHP 5.3 ?: operator

Just for completeness, another way to achieve it is to pull operator rank:



 $page = (int)$_GET["page"]  or  $page = 1;



Many people perceive this as unreadable however, though it's shorter than isset() constructs.



Or if you are using input objects or any other utility class:



 $page = $_GET->int->default("page", 1);

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...