Whats new in PHP 8.4
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
php84/Books.php

26 lines
549 B

<?php
interface HasAuthors {
public string $credits { get; }
public Author $mainAuthor { get; set; }
}
class Author {
public function __construct(public private(set) string $name) {}
}
class Book implements HasAuthors {
public string $credits {
get => "Authors: David Smith\n";
}
public Author $mainAuthor {
get => new Author("Smith");
set => throw new Exception("Main author cannot be changed.");
}
}
$book = new Book();
echo $book->credits;
$author = $book->mainAuthor;
echo $author->name;