I have the following php code:
<?php
class Session {
public function __construct() {
if (!session_id()) {
session_start();
}
if (!is_array($_SESSION['messages'])) {
$_SESSION['messages'] = [];
}
echo is_array($_SESSION['messages']);
}
public function AddMessage($msg="") {
array_push($_SESSION['messages'], $msg);
}
public function GetMessages() {
$messages = $_SESSION['messages'];
unset($_SESSION['messages']);
return $messages;
}
}
$session = new Session();
?>
And the output of $session->AddMessage('message') is:
1
Warning: array_push() expects parameter 1 to be array, null given in ...\Session.php on line 16
so is_array clearly says that $_SESSION['messages'] IS an array. What am I missing?