I have a problem with classes in PHP, I want to assign values received from the database to a private variable so that I can then use them in class functions. But in doing so I get the error:
Fatal error: Constant expression contains invalid operations in ..\database.php on line 21
Here is my code:
class Ustawienia {
private $current_id = $_SESSION['user_id'];
private $uprawnienia = get_premissions(); //here i get a fatal error
private function get_premissions() {
$query_premissions = OpenCon()->prepare("SELECT * FROM uprawnienia WHERE id_pracownicy = :id");
$query_premissions -> bindValue(':id', $current_id, PDO::PARAM_INT);
$query_premissions -> execute();
return $query_premissions -> fetch();
}
public function dostep_ustawienia() {
if($uprawnienia['dostep_ustawienia']) return true;
return false;
}
}
I tried to change return to echo but i didn't helped. How can i achieve that? Thanks for any help.