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!
var_dump($test);
? – ccKep Jul 5 at 2:26formErrors
isn't even in your posted code. Show us what/how you're using this. – Fred -ii- Jul 5 at 2:28$formMessages
through$this->formMessages
. Take a look: ideone.com/wUCfkT (check my line 12 and compare to yours) – Jeremy Jul 5 at 2:32