Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4557654
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:32:21+00:00 2026-05-21T17:32:21+00:00

Please could someone help with the following? We have the following classes: abstract class

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T17:32:22+00:00Added an answer on May 21, 2026 at 5:32 pm

    Works for me : http://codepad.viper-7.com/Ool7zn

    <?php
    
    abstract class Element
    {
        protected $errors = array();
    
        public function setError($error)
        {
            $this->errors[] = $error;
        }
    
        public function getErrors()
        {
            return "<li>".implode("</li>\n",$this->errors);
        }
    }
    abstract class Container extends Element{}
    abstract class Field extends Container{}
    class Text extends Field{}
    
    $t = new Text;
    $t->setError('foobar');
    
    echo $t->getErrors();
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could someone please help me out with the following problem in java. I have
I wonder whether someone can help me please. I have the following xml file
Could someone please help with the following jQuery I need all jQuery UI buttons
Could someone please help me with the following issue. You will see that in
Could someone please help me to understand why the following block of code keeps
Could someone please help me figure out what is wrong with the following code
Please could someone experienced in PHP help out with the following. Somewhere in my
Could someone please help me in here, I'm just a beginner who want to
Could someone please help explain why I can't get this to work? I properly
I've recently written this with help from SO. Now could someone please tell me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.