A title that stays put

Exercise 2 of 9 in chapter 2 · 100 XP · 6 objectives checked by tests

Topics covered: readonlyVisibilityMethod$this

Disaster: the front page says the festival is canceled! Léo has struck again, and one line was all it took to change a title after the fact. A published article should not move anymore, and nobody outside the class has any business touching its text.

Your mission

  1. Make every property of Article read-only with readonly, then delete Léo's line, which now makes the page crash.
  2. Make the text private: private readonly string $texte.
  3. Add a public method chapo(): string (standfirst) to Article, which returns the standfirst: the first 80 characters followed by “…” for a long text, the whole text otherwise.
  4. In afficherArticle(), use $article->chapo().

Reminder

public, private: visibility says who may touch a property or call a method. readonly forbids changing a value after construction. A method is a function that lives in the class; there, it reaches the object through $this. That is the idea of encapsulation: the class keeps its data to itself, and offers methods to work with it.