I'm experiencing an issue with a session message system available here where the messages aren't being displayed. After a lot of trial and error I decided to simplify the issue I was experiencing down to the following for the purposes of testing:
<?php
ini_set('error_reporting', E_ALL);
define('script_access', true);
if (!isset($_SESSION)) {
session_start();
}
require('../framework/classes/messages.php');
$msg = new Messages();
class Test {
public $foo;
public function __construct() {
$this->foo = new Messages();
}
public function create_form() {
if (isset($_POST['submit']) == 'Submit') {
$this->form_process();
}
echo '<form action="' . $_SERVER['PHP_SELF'] . '?id=1&table=about" method="post">';
echo '<input name="submit" type="submit" id="submit" value="Submit">';
echo '</form>';
}
public function form_process() {
//$new = new Messages();
$this->foo->add('s', 'new message from');
header("Location: message.php?proc=true");
}
}
if ($_GET['proc'] == true) {
echo 'should be a message here<br>';
echo $msg->display();
exit;
} else {
$test = new Test();
$test->create_form();
}
?>
After some messing around I added the now commented out $new = new Messages();
to a subroutine and the messages appear. However, leaving it commented out they do not appear. I'm not sure why I have to redeclare a class that I've already declared in the constructor. Does anybody know why this is happening and how I can make it so that I only have to initiate the class in the constructor instead of in the subroutine?