I'm trying to get a :"var = new class" , but i need this variable to be global in the file (or superglobal) and it needs to be rememberd.
<?php
include 'game.php';
include 'button.php';
include 'beurt.php';
include 'scores.php';
include 'round.php';
include 'speelveld.php';
include 'player.php';
include 'cells.php';
if(isset($_POST['action']) && !empty($_POST['action'])) {
$action = $_POST['action'];
if (isset($_POST['Val']) && !empty($_POST['Val'])) {
$Val = $_POST['Val'];
}
switch ($action) {
case 'Start' :
echo"<script>alert('new game started')</script>";
$Game = new Game;
break;
case 'ButtonClickStart':
$Game->ButtonClickStart();
break;
case 'ButtonClickStop' :
$Game->ButtonClickStop();
break;
case 'ClickCell' :
$Game->ClickCell( $Val );
break;
// ...etc...
}
}
?>
i call this file trough $ajax and try to make it execute Functions to the Class, however what i cant seem to get past is that : "$Game = new Game();" should only be executed onces and it needs to be remeberd. I understood it could be done trough a: static $game = '' , but php didnt seem to like static in combination with a new class.
At first i tried to declare $Game below the includes, however that lead to it executing that everytime upon calling the file trough Ajax, setting $Game to the construction value's.
now what i want cant figure out is, is there a way to only execute $Game = new Game once while getting remeberd (so it doesnt lose the data after the function is done) And being able to use the var in the other cases
Case start gets activated by the index on a onload function, but i it doesnt seem to remeber the data also as last note im very new to php in general so any info is very welcome