Please could someone help with the following?
We have the following classes:
- abstract class Element{}
- abstract class Container extends
Element{} - abstract class Field extends
Container{}
The ‘Element’ base class has the following properties and methods:
//Element class
private $errors = array();
public function __construct()
{
}
public function setError($error)
{
$this->errors[] = $error;
}
public function getErrors()
{
return "<li>".implode("</li>\n",$this->errors);
}
The ‘Container’ just groups the elements (objects).
The ‘Field’ class calls the ‘setError’ method of the base class and passes a value like this:
//Field class
$this->setError("foo");
For some reason the ‘errors’ property in the base class doesn’t get the value added to it and Im guess its something to do with how the object is instantiated because obviously the abstract classes are not instantiated by default.
The only instantiation of the field is in its inherited form which is:
Text extends Field{}
$field = new Text(etc, etc)
How would you get about resolving this?
Works for me : http://codepad.viper-7.com/Ool7zn