...

/

Solution Review: Static Methods & Properties and Traits

Solution Review: Static Methods & Properties and Traits

Let's look at the solution of the Static Methods & Properties and Traits challenge.

We'll cover the following...

Solution

Press + to interact
<?php
interface User {}
trait Writing {
abstract public function writeContent();
}
class Author implements User {
use Writing;
public function writeContent() {
return "Author, please start typing an article";
}
}
class Commentator implements User {
use Writing;
public function writeContent() {
return "Commentator, please start typing your comment";
}
}
class Viewer implements User {}
function test()
{
$author1 = new Author();
$commentator1 = new Commentator();
return $author1 -> writeContent() . " and " . $commentator1 -> writeContent();
}
echo test()
?>

Explanation

  • Line 2: We
...