Who wrote this?

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

Topics covered: CompositionObject inside an objectMethod

Gaston finally agreed to sign the article about the mayor's cat. Readers, for their part, want to know who is talking to them. Madame Lou would like each article to be signed with the name and the role of its author: “By Gaston, village constable”.

Your mission

  1. Declare an Auteur (author) class whose constructor receives string $nom (name) and string $role, both read-only, and a signature(): string (byline) method that returns “Gaston, village constable”.
  2. Create each of the three authors only once, in variables: Madame Lou (“editor-in-chief”), Gaston (“village constable”) and Odette (“baker”).
  3. The auteur property of Article becomes an Auteur. Give each article its own. The article about the mayor's cat, signed “the newsroom” until now, is now by Gaston.
  4. In afficherArticle(), sign each article with By followed by its author's byline: “By Gaston, village constable”. Every article now has an author, so the “By the newsroom” case goes away.

Reminder

A property can hold another object: this is called composition. The article does not copy Gaston's name, it points to Gaston. If Gaston changes roles, both of his articles follow. Arrows can be chained: $article->auteur->signature().