Skip to content

Commit

Permalink
Fix notice about duplicate session when multiple instances are created
Browse files Browse the repository at this point in the history
  • Loading branch information
susanBuck committed Nov 1, 2021
1 parent 2b8a343 commit c198dd8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class Game
*/
public function __construct(bool $persistResults = false, int $maxResults = 5, string $timezone = 'America/New_York')
{
session_start();
if (session_status() !== PHP_SESSION_ACTIVE) {
session_start();
}

date_default_timezone_set($timezone);

Expand Down
5 changes: 4 additions & 1 deletion tests/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@

$game->play('rock');

var_dump($game->getResults());
var_dump($game->getResults());

# Make sure we can start a new instance without warning about session being already started
$game2 = new RPS\Game(true);

0 comments on commit c198dd8

Please sign in to comment.