Skip to content

Commit

Permalink
Change asymmetric visibility example to show how it simplifies code
Browse files Browse the repository at this point in the history
The previous example wasn't very helpful, since it only showed invalid code that will error (and could just as easily be replaced with a readonly property).
  • Loading branch information
theodorejb committed Nov 20, 2024
1 parent 420a34a commit ff4b85e
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions releases/8.4/release.inc
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,20 @@ PHP
<<<'PHP'
class PhpVersion
{
public string $version = '8.3';
}
private string $version = '8.3';
$phpVersion = new PhpVersion();
var_dump($phpVersion->version); // string(3) "8.3"
$phpVersion->version = 'PHP 8.4'; // No error
public function getVersion(): string
{
return $this->version;
}
public function increment(): void
{
[$major, $minor] = explode('.', $this->version);
$minor++;
$this->version = "$major.$minor";
}
}
PHP

); ?>
Expand All @@ -178,11 +186,14 @@ PHP
class PhpVersion
{
public private(set) string $version = '8.4';
}
$phpVersion = new PhpVersion();
var_dump($phpVersion->version); // string(3) "8.4"
$phpVersion->version = 'PHP 8.3'; // Visibility error
public function increment(): void
{
[$major, $minor] = explode('.', $this->version);
$minor++;
$this->version = "$major.$minor";
}
}
PHP
); ?>
</div>
Expand Down

0 comments on commit ff4b85e

Please sign in to comment.