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 4557616
In Process

The Archive Base Latest Questions

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

Please advise what’s going on here? We have the following classes working together: An

  • 0

Please advise what’s going on here?

We have the following classes working together:

  • An abstract base class ‘form element’
  • An abstract ‘container’ class that
    extends the form element class and
    groups form elements
  • A ‘field’ class that extends the
    container

In the ‘field’ class we call a method from the ‘form element’ class named ‘setErrors($vars)’ that sets a property named ‘hasErrors’. $vars carries a boolean.

There is another method named ‘hasErrors()’ in the ‘form element’ class that we try to call in the ‘field’ class to test the result of the boolean previously set however it returns false.

The hasErrors property that is initially declared as false is not being overwritten?

Form Element Class(Base)

private $hasErrors = false;

public function setErrors($flag)
{
...
$this->hasErrors = $flag;
...
}

public function hasErrors()
{
return $this->hasErrors;
}

Field Class

public function validate($value)
{
...
$this->setErrors($foundErrors);//$foundErrors only local to this method
...
}

public function getField()
{
...
   if($this->hasErrors())
   {
   //do something...
   }
...
}

Why is the property ‘hasErrors’ not being overwritten? Would this have something to with the scope of inheritance between the different classes?

Not sure how this works but thanks in advance.

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

    I’m sorry to not answer your question directly, but the other answers are misleading and feel I have to step in a bit. Especially since similar test code works fine.

    Have you tried stripping your code down to the basics? Just as a test, I created the following which works fine:

    <?php
    class test {
            private $var = 'unset';
            public function setVar($val) {
                    $this->var = $val;
            }
            public function getVar() {
                    return $this->var;
            }
    }
    class another extends test {
            public function __construct() {
                    echo $this->getVar() . "\n";
                    $this->setVar('set');
                    echo $this->getVar() . "\n";
            }
    }
    class third extends another {
            public function __construct() {
                    parent::__construct(); // This will output 'unset\nset\n'
                    $this->setVar('set second');
                    echo $this->getVar() . "\n";
            }
    }
    $a = new third();
    

    Output:

    > php tmp.php 
    unset
    set
    set second
    

    Updated as per comment, same output:

    class another extends test {
            public function methodAnother() {
                    echo $this->getVar() . "\n";
                    $this->setVar('set');
                    echo $this->getVar() . "\n";
            }
    }
    class third extends another {
            public function methodThird() {
                    $this->setVar('set second');
                    echo $this->getVar() . "\n";
            }
    }
    $a = new third();
    $a->methodAnother();
    $a->methodThird();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please advise.. In the following code(Tested. Will work fine) public class Exp_Test { public
Can anyone please advise where i'm going wrong with the following? I want the
Getting a segmentation fault for the following code. Please advise. struct columns { char*
please advise on the following, and if you were to do something different please
Please advise me. Winforms app, C#. I have a user control (UC) that contains
Can you please advise what is wrong here. This is how my method in
Please advise me on this. I have both Wcf service (which will be responsible
New to learning PHP form validation on same page. Please advise as to why
Please advise me, what wrong with my following code: <a href=<?php echo $_url; ?>
Good day, please advise why am I getting following exception. I'm EclipseLink beginner, I'm

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.