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.
This is the class:
class Message
{
public $formMessages = array();
public function __construct()
{
}
public function writeFormMessage($field, $message)
{
$formMessages[$field] = $message;
}
public function getFormMessages()
{
return $this->formMessages;
}
}
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.
$test = $message->getFormMessages();
It fails this predicate, though it doesn't seem to be seeing the array anyhow:
if (!empty($test))
{
}
The php error was 'Undefined variable: formMessages in C:\xampp\htdocs\test\classes\message.class.php on line 45'
Edit: Thanks all!