Question du test PHP8

Comment utiliser la méthode `__construct()` en PHP.

Difficile

Qu'affiche cet exemple ?

<?php

class Period {
    private \DateTimeInterface|null $startDate;

    public function __construct(?\DateTimeInterface $startAt)
    {
            $this->startDate = $startAt;
    }

    public function getStartDate(): \DateTimeInterface
    {
       return $this->startDate;
    }
}

$period = new Period(new \DateTimeImmutable("2020-11-26"));
$period->__construct();

$dateAsString = $period->getStartDate()?->format('Y');

echo $dateAsString;
Auteur: Amine BouchamStatut : Publiée(Mise à jour)Question passée 107 fois
Modifier
2
Évaluations de la communauté
developer avatar
Vincent Cotro
05/09/2022
Ahah, merci pour la correction et bien vu 😂