$_GET
is globally accessible, but $questinID
isn't.
What you can do is either access $_GET
from within the class.
class Question {
public function __construct() {
$this->id = isset($_GET['question']) ? $_GET['question'] : 0;
}
}
Or pass it to the constructor.
$questionID = isset($_GET['question']) ? ($_GET['question']) : 0;
class Question {
public function __construct($questionID) {
$this->id = $questionID;
}
}
$question = new Question($questionID);
The second one is the preferred method, since it allows you to create questions in a more flexible way which, for instance, makes it easier to create unit tests.