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 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 advise the current best practice around Date and Calendar types. When
Could someone please advise? If const in C++ defaults to internal linkage, why do
Could someone please demystify interfaces for me or point me to some good examples?
Could someone please advise in the context of a ASP.Net application is a shared/static
Could someone please advise me on the best method for saving image files to
Could someone please give me some advice/ideas about how to deal with the situations
Could someone please advice why i have a memory leak in this code? I
could someone please point me in the right direction, I currently have a searchable
Could someone please advise on what my options are when it comes to video
Please could someone post an example of how to check if an element exists

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.