DEV Community

Discussion on: SOLID PRINCIPLES: To start with Object-oriented programming

Collapse
 
vlasales profile image
Vlastimil Pospichal

SRP:

<?php declare(strict_types=1);

class Book implements JsonSerializable {
    private $author;

    function __construct(string $author) {
        $this->author = $author;
    }

    public function getAuthor() {
        return $this->author;
    }

    public function jsonSerialize() {
        return $this->getAuthor();
    }

}

$book = new Book('Author');
echo json_encode($book);