Skip to content

Readonly properties #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
27 changes: 21 additions & 6 deletions spec/14-classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ class. A member with `protected` visibility may be accessed only from
within its own class and from classes derived from that class. Access to
a member with `public` visibility is unrestricted.

Properties, but not methods, of a class can be marked as `readonly`. If the
property is marked as `public` and `readonly`, it is readable from the public
context but only writeablee from the protected context (within own class and
derived classes). If the property is marked as `protected` and `readonly`, it is
readable from the protected context but only writeable from the private context
(within own class). Properties cannot be both `private` and `readonly`, nor
`static` and `readonly. For the purposes of `readonly`, unsetting and obtaining
a reference to a property are considered to be writing.

The *signature* of a method is a combination of the parent class name,
that method's name, and its parameter list, including type hints and
indication for arguments passed using byRef, and whether the resulting
Expand Down Expand Up @@ -243,8 +252,8 @@ class Point
{
private static $pointCount = 0; // static property

private $x; // instance property
private $y; // instance property
readonly protected $x; // instance property
readonly protected $y; // instance property

public static function getPointCount() // static method
{
Expand Down Expand Up @@ -406,8 +415,10 @@ $col = Automobile::DEFAULT_COLOR;

<i>property-modifier:</i>
var
<i>visibility-modifier static-modifier<sub>opt</sub></i>
<i>static-modifier visibility-modifier<sub>opt</sub></i>
<i>visibility-modifier readonly-modifier<sub>opt</sub></i>
<i>readonly-modifier visibility-modifier<sub>opt</sub></i>
<i>visibility-modifier static-modifier<sub>opt</sub></i>
<i>static-modifier visibility-modifier<sub>opt</sub></i>

<i>visibility-modifier:</i>
public
Expand All @@ -417,6 +428,9 @@ $col = Automobile::DEFAULT_COLOR;
<i>static-modifier:</i>
static

<i>readonly-modifier:</i>
readonly

<i>property-initializer:</i>
= <i>constant-expression</i>
</pre>
Expand Down Expand Up @@ -446,8 +460,9 @@ class Point
{
private static $pointCount = 0; // static property with initializer

private $x; // instance property
private $y; // instance property
public readonly $x; // instance property
public readonly $y; // instance property
private $cache; // instance property
...

}
Expand Down