loading...

re: SOLID PRINCIPLES: To start with Object-oriented programming VIEW POST

FULL DISCUSSION
 

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);
Code of Conduct Report abuse