I have a main file (framework.php) that require
s a few classes. For simplicity of my question lets assume only messages with the class Messages
and automate with the class Automate
. The messages class stores session messages that appear to the user on the frontend whenever they refresh their page .etc. When I add a message in Automate
I do so via $msg = new Messages; $msg->add('s', 'Hello World!');
However I keep repeating $msg = new Messages
everytime I want to add a $msg
, and because this is messy, I want to just call the class once. So I initialize the class in the constructor like so:
class Automate
{
protected $msg;
//public $connection;
public $cke;
public $debug = false;
public $disallow_insert;
public $bImgUp = BACKEND_IMAGE_UPLOAD_PATH;
public $fImgUp = FRONTEND_IMAGE_UPLOAD_PATH;
public function __construct() {
global $disallow_insert;
$this->disallow_insert = $disallow_insert;
$this->cke = (bool) self::ckeCheck();
$this->msg = new Messages();
}
and in my main file I add it $msg = new Messages();
so I can just call the display function echo $msg->display();
However this method does not work (no errors, but still), the only thing that seems to work is when I initialize the $msg = new Messages();
before every add or display. What am I doing wrong?
I should mention I'm using this session based message script.
UPDATE:
I have determined the the messages are getting added by commenting out the clear
function in the messages class. It almost seems as though the variable is getting unset before displaying.