DEV Community

Dimitrios Desyllas
Dimitrios Desyllas

Posted on

How I can reset private instance variables if an exception is not thrown in a classe's public methods?

What I want to achieve is to have a mechanism that sets and resets a guard value so I can avoid an object to be saved if not all the requirements are met.

So how In the question bellow I have a private variable that tells me if I should proceed into the object save or not.

I have the following class that implements the logic for setting a booking:

class DBRecord
{
   public $id
   public $value1;
   public $value2;
}

class CreateADbRecord
{

   private $dbRecord;
   private $canSave = true;

   public function __construct()
   {
     $this->dbRecord = new DBRecord();
   }

   public function setValueOne($value)
   {
      if(is_numeric($value) && $value < 0

But I want to implement a way that allows me to reset it in case that everything is done as it should.

Can you help me with that?

Top comments (0)