You must be registered for see images
PHP 8.4 is scheduled to be released tomorrow, and one exciting feature we haven't covered yet is Asymmetric Property Visibility. Starting in PHP 8.4, properties may also have their visibility set asymmetrically with a different scope for reading and writing. Here's an example from the
You must be registered for see links
:
Code:
class Book
{
public function __construct(
public private(set) string $title,
public protected(set) string $author,
protected private(set) int $pubYear,
) {}
}
class SpecialBook extends Book
{
public function update(string $author, int $year): void
{
$this->author = $author; // OK
$this->pubYear = $year; // Fatal Error
}
}
$b = new Book('How to PHP', 'Peter H. Peterson', 2024);
echo $b->title; // How to PHP
echo $b->author; // Peter H. Peterson
echo $b->pubYear; // Fatal Error
Follow our
You must be registered for see links
post to get updates as PHP 8.4 is released on November 21st!