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

  • Home
  • SEARCH
  • 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 4558786
In Process

The Archive Base Latest Questions

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

Please could someone advise? We have an abstract base class with a few properties

  • 0

Please could someone advise?

We have an abstract base class with a few properties and some methods.

The methods(with parameters) are being called from inherited classes with the common intention of setting the passed parameters to the properties of the base class except they don’t appear to override the default value.

If I set a value(for testing purposes) in the constructor of the abstract(base) class it works fine and anything else passed to the constructor works but what we want to do is get the setErrors method to actually set the value of the property.

Example:

//abstract base class

private $errors = array();//the property we want to overide

public function __construct()
{
$this->errors[] = "This is a required field";//for testing purposes only this works
}

public function setErrors($error)
{
var_dump($error);//this proves that $error is passing something...
$this->errors[] = $error;//this doesnt work(override the property)
var_dump($this->error);//the property now has the $error value...
}

public function getErrors()
{
return "<li>".implode("</li>\n",$this->errors);
}

I’m not sure if this is something to do with the base class being abstract i.e. as it doesnt get instantiated. Please could someone explain why this doesn’t work?
Thanks in advance for taking an interest.

Edit
WE ARE NOT TRYING TO INHERIT THE PRIVATE PROPERTY FROM THE BASE CLASS

What we want to do is override the property with the set method and then use a public get method to return the property.

  • 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:41:49+00:00Added an answer on May 21, 2026 at 5:41 pm

    You should declare $errors as protected instead of private. Read more about Class and Objects visibility 😉

    Update:

    Ok, maybe I understand your problem now 😛

    Try to modify your setErrors like so:

        public function setErrors($error)
        {
            var_dump($error);//this proves that $error is passing something...
            $this->errors = (array) $error;//this works (override the property)
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could someone please demystify interfaces for me or point me to some good examples?
Could someone please explain what the for loop in this class does? Specifically the
Could someone please tell me which objects types can be tested using Regular Expressions
Could someone please explain the best way to connect to an Interbase 7.1 database
Could someone please point me toward a cleaner method to generate a random enum
Could someone please explain? I couldn't find anything on the internet, everything talks about
I've recently written this with help from SO. Now could someone please tell me
Could someone simply explain the 3 phases in the Flash Event framework, please? By
Could somebody please name a few. I could given time, but this is for
Please could someone give me an example in batch of something like: IF test.txt

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.