From 3fdd0064d0853bbe72ba62b245738b56b75a0fce Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Thu, 23 Oct 2014 23:46:41 +0100 Subject: [PATCH] Readonly properties --- spec/14-classes.md | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/spec/14-classes.md b/spec/14-classes.md index dc9f984d..e937e694 100644 --- a/spec/14-classes.md +++ b/spec/14-classes.md @@ -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 @@ -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 { @@ -406,8 +415,10 @@ $col = Automobile::DEFAULT_COLOR; property-modifier: var - visibility-modifier static-modifieropt - static-modifier visibility-modifieropt + visibility-modifier readonly-modifieropt + readonly-modifier visibility-modifieropt + visibility-modifier static-modifieropt + static-modifier visibility-modifieropt visibility-modifier: public @@ -417,6 +428,9 @@ $col = Automobile::DEFAULT_COLOR; static-modifier: static + readonly-modifier: + readonly + property-initializer: = constant-expression @@ -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 ... }