title: 'Undefined variable' error when returning an array from a function
body: <p>Essentially, I have a message class with a function that can write to an array. I want to then return that instance of an array through a function when called.</p>
  
  <p>This is the class:</p>
  
  <pre><code>class Message
  {
      public $formMessages = array();
  
      public function __construct()
      {
      }
  
      public function writeFormMessage($field, $message)
      {
          $formMessages[$field] = $message;
      }
  
      public function getFormMessages()
      {
          return $this-&gt;formMessages;
      }
  }
  </code></pre>
  
  <p>Here is how I am attempting to grab the formMessages array from another file. Yes I already have an instance of the Message class in said file.</p>
  
  <pre><code>$test = $message-&gt;getFormMessages();
  </code></pre>
  
  <p>It fails this predicate, though it doesn't seem to be seeing the array anyhow:</p>
  
  <pre><code>if (!empty($test))
  { 
  }
  </code></pre>
  
  <p>The php error was 'Undefined variable: formMessages in C:\xampp\htdocs\test\classes\message.class.php on line 45'</p>
  
  <p><strong>Edit</strong>: Thanks all!</p>