Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion language/oop5/visibility.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ $obj2->printHello(); // Shows Public2, Protected2, Undefined
<sect3 xml:id="language.oop5.visibility-members-aviz">
<title>Asymmetric Property Visibility</title>
<simpara>
As of PHP 8.4, properties may also have their
As of PHP 8.4, object properties may also have their
visibility set asymmetrically, with a different scope for
reading (<literal>get</literal>) and writing (<literal>set</literal>).
Specifically, the <literal>set</literal> visibility may be
Expand Down Expand Up @@ -119,6 +119,33 @@ $b->title = 'How not to PHP'; // Fatal Error
$b->author = 'Pedro H. Peterson'; // Fatal Error
$b->pubYear = 2023; // Fatal Error
?>
]]>
</programlisting>
</example>
<simpara>As of PHP 8.5, set visibility may also be applied to static properties of classes.</simpara>
<example>
<title>Asymmetric Property visibility</title>
<programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php
class Manager
{
public private(set) static int $calls = 0;

public doAThing(): string
{
self::$calls++;
// Do other stuff.
return "some string";
}
}

$m = new Manager();

$m->doAThing(); // Works
print Manager::$calls; // Works
Manager::$calls = 5; // Fatal error
?>
]]>
</programlisting>
</example>
Expand Down