This is a followup question to this question
If I declare this as a singleton class:
// Server.php
class Server {
  private $stopper;
  private static $instance;
  public static getInstance() { 
    if(!isset(self::$Server)) 
      self::$Server = new static();
    return self::$Server; 
  }
  public function setStopper() { $this->stopper = TRUE; }
  public function startServer() { 
    $self = $this;
    $consumer = new Consumer();
    $consumer->onConsume(function($data) use($self, $consumer) {
      // some processing
      if($self->getStopper()) { // always false
         $consumer->stop();
         $self->stopServer();
      }
    });
    $consumer->consume();
  }
  public function stopServer() { ... }
}
And used following script to start the server:
// start.php
$server = Server::getInstance();
$server->startServer();
And following script to set the stopper:
// stop.php
$server = Server::getInstance();
$server->setStopper();
It doesn't work: the stopper is still false (tried echoing)! Also I have tried using sessions instead.
// start.php
$server = new Server();
session_start();
$_SESSION['server'] = $server;
session_write_close();
$server->startServer();
// stop.php
session_start();
$server = $_SESSION['server'];
$server->setStopper(TRUE);
But running the stop.php throws following error: Undefined index: server