1
I have the following class:
abstract class Weeks
{
  protected $year;
  protected $this_week;
  protected $last_week;
  /**
  * @param $date deverá ser no formato new DateTime().
  **/
  public function __construct($date)
  {
    $this->year = $date->format('Y');
    $this->this_week = $date->format('W');
    $this->last_week = ($date->sub(new DateInterval('P1W')))->format('W');
  }
}
There I extend it within other classes for example:
class Training_Load_Week extends Weeks
{
      private $trainingLoadThisWeek;
      /**
      * @param $training_load é um array multidimensional contendo todos os treinos separados por [ano][numero_da_semana](treinos)
      **/
      public function setTrainingLoadThisWeek($training_load)
      {
        $this->trainingLoadThisWeek = array_sum( $training_load[$this->year][$this->this_week] );
      }
      public function getTrainingLoadThisWeek()
      {
        return $this->trainingLoadThisWeek;
      }
}
$training_load_week = new Training_Load_Week($today);
$training_load_week->setTrainingLoadThisWeek($arr_tl);
And this:
class Training_Load_Last_Week extends Weeks
{
      private $trainingLoadLastWeek;
      /**
      * @param $training_load é um array multidimensional contendo todos os treinos separados por [ano][numero_da_semana](treinos)
      **/
      public function setTrainingLoadLastWeek($training_load)
      {
        $this->trainingLoadLastWeek = array_sum( $training_load[$this->year][$this->last_week] );
      }
      public function getTrainingLoadLastWeek()
      {
        return $this->trainingLoadLastWeek;
      }
}
$training_load_last_week = new Training_Load_Last_Week($today);
$training_load_last_week->setTrainingLoadLastWeek($arr_tl);
What is happening is the following, the date is not always starting on the date given in the variable $today
It continues from where it left off in the use of the first class, for example, it was supposed to be week 34 to $this->week and week 33 to $this->last_week
But when I call the second class, it does not use those same values, it continues from where it left off in the previous class uses, that is, returns the values $this->week like 33 and $this->last_week like 32, but it should be 34 and 33 again.
I don’t understand why.
because you need to call the abstract class builder !!! and be explicit in that statement.
– novic
There is already an explanation on the subject: https://answall.com/questions/45297/posso-declarar-um-construct-construct-nas-classes-filhas-quando-a-classe-m%C3%A3e-%C3%A9-abstract-e
– novic