Skip to content

Instantly share code, notes, and snippets.

@adrian-enspired
Created August 25, 2018 20:50
Show Gist options
  • Save adrian-enspired/1f5fde8dd9e4668d5f7f5aac6d809f7b to your computer and use it in GitHub Desktop.
Save adrian-enspired/1f5fde8dd9e4668d5f7f5aac6d809f7b to your computer and use it in GitHub Desktop.
<?php
class Wrong {
public function getX() {
return $_GET['x'] ?? 'default x';
}
}
class Right {
public function __construct(array $params) {
$this->params = $params;
}
public function getX() {
return $this->params['x'] ?? 'default x';
}
}
$wrong = new Wrong();
echo $wrong->getX();
$right = new Right($_GET);
echo $right->getX();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment