0

This is a very silly question, but I don't know what's wrong. I can't get the value of a private variable through a public method. I'm using CodeIgniter.

class someClass extends MY_Model {
  private $table = 'sometable';
  public function getTable() {
    return $this->table;
  }
  public function updateTable($data) {
    $this->db->update($this->getTable(), $data);
  }
}

When I call this method from the controller, I get this message:

Fatal error: Access level to someClass::$table must be public (as in class MY_Model) in /some/path/someclass.php on line 38

What have I done wrong? Thank you.

1 Answer 1

6

Your parent class MY_Model is declaring that field with public scope, so you must adhere to that in your child class.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much. I didn't realize $table is a variable in the super class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.