In multiple place on a script I have ...
if (isset($_GET['event-id']) { ... } Would it slow things down to call the key twice? Should I just define a new var like ...
$event_id = $_GET['event-id']; if ($event_id) { ... } This also raise an E_NOTICE if $_GET['event-id'] is not set:
$event_id = $_GET['event-id']; I prefer
$event_id = isset($_GET['event-id']) ? $_GET['event-id'] : false; especially when I am going to use $event_id multiple times. Then, I can write:
if($event_id){ //do your code } or in cases that an empty $event_id is possible:
if($event_id !== false){ //do your code } The best would be to assign this onto a var and validate it before all further processing, to get sure this var contains no prohibited content.
I don't think it would slow down as it's only a Array call, but it is a security gap.
Edit:
Also if it isn't set you could define a default value.
If there is really a need to check $_GET['event-id'] at many places in your code, you can set it once using Ternary Operator
$event_id = isset($_GET['event-id']) ? $_GET['event-id'] : '' ; Then you can use it like if ($event_id) or if(empty($event_id)) or if(!empty($event_id)) depending upon your need of condition.