title: Multiple class methods adding to string
body: <p>I have a string of data that will be written to a file as a log of events, so I need this string available from the time the page begins to load to the time it is completed loading, at which time the contents of the string are written to the log file.</p>
  
  <p>I am able to add to this string across some classes, but not others so it has me confused. When it doesn't work I get an 'allowed memory size of ... exhausted' error.</p>
  
  <p>FILE: index.php</p>
  
  <pre><code>spl_autoload_register(function($class) {
  
      if (file_exists(dirname(__FILE__).'/classes/'.$class.'.class.php')) {
  
          include dirname(__FILE__).'/classes/'.$class.'.class.php';
  
      }
  
  });
  
  $App = new Core();
  
  $App-&gt;Visitor-&gt;getIP(); // This will exhaust memory...why?
  $App-&gt;Settings-&gt;hello(); // Works
  $App-&gt;writeLog('in my index file...'); // Works
  
  $App-&gt;viewLog();
  </code></pre>
  
  <p>FILE: /classes/Core.class.php</p>
  
  <pre><code>class Core {
  
      public static $logContent;
  
      public function __construct() {
  
          $this-&gt;initialize();
  
      }
  
      private function initialize() {
          self::$logContent = 'Lets start...';
          $this-&gt;Visitor = new Visitor($this);
          $this-&gt;Settings = new Settings($this);
          $this-&gt;Cache = new Cache($this);    
      }
  
      public function writeLog($action) {
        self::$logContent .= $action;
      }
  
      public function viewLog() {
        echo self::$logContent;
      }
  
  }
  </code></pre>
  
  <p>FILE: /classes/Visitor.class.php</p>
  
  <pre><code>class Visitor {
  
      private $App;
  
      public function __construct($App) {
  
          $this-&gt;App = $App;
  
      }
  
      public function getIP() {
  
          $this-&gt;App-&gt;writeLog('getting ip...'); // Exhausts memory
  
          if (isset($_SERVER['REMOTE_ADDR'])) {
  
              return $_SERVER['REMOTE_ADDR']; 
  
          } else {    
  
              return false;   
          }
  
      }
  
  }
  </code></pre>
  
  <p>FILE: /classes/Settings.class.php</p>
  
  <pre><code>class Settings {
  
      private $App;
  
      public function __construct($App) {
  
          $this-&gt;App = $App;
  
      }
  
  
      public function hello() {
          $this-&gt;App-&gt;writeLog('getting ip...');
          return 'hello';
  
      }
  
  }
  </code></pre>
  
  <p>What I can't figure out is that both <code>Visitor.class.php</code> and <code>Settings.class.php</code> are setup the same way with the same constructor and yet one will work and the other won't.</p>
  
  <p>So as you can see, I made a static string that everything throughout the app can add to, then later this string will be written to a file one time. Am I going about this the wrong way?</p>