rfc:propertygetsetsyntax-as-implemented:change-requests
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:propertygetsetsyntax-as-implemented:change-requests [2012/10/21 17:52] – cpriest | rfc:propertygetsetsyntax-as-implemented:change-requests [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== v1.1 -> v1.2 ====== | ====== v1.1 -> v1.2 ====== | ||
+ | * [[rfc/ | ||
+ | |||
===== Current Consensus Changes ===== | ===== Current Consensus Changes ===== | ||
==== Syntax Change ==== | ==== Syntax Change ==== | ||
- | Change | + | < |
+ | |||
+ | Allow syntax to use parenthesized syntax as well so that both a [TypeHint] and $value | ||
<code php> | <code php> | ||
class TimePeriod { | class TimePeriod { | ||
Line 17: | Line 22: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | The abbreviated syntax is also allowed as per 1.1 RFC. | ||
+ | |||
+ | ==== read-only / write-only keywords ==== | ||
+ | < | ||
+ | |||
+ | read-only / write-only keywords will be eliminated, the issue will be pushed to userland developers who can enforce the same by coding something like this: | ||
+ | |||
+ | <code php> | ||
+ | class TimePeriod { | ||
+ | private $Seconds; | ||
+ | |||
+ | public $Hours { | ||
+ | get() { return $this-> | ||
+ | private final set($value) { throw new Exception(" | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | This was previously being debated, the full details of this are in the last section under " | ||
==== Automatically Implemented Accessors ==== | ==== Automatically Implemented Accessors ==== | ||
+ | [[https:// | ||
+ | |||
v1.1 properties shadow (or over-ride) accessors, so if an accessor exists and a property is defined (only possible from within the accessors setter), then the property would shadow the accessor. | v1.1 properties shadow (or over-ride) accessors, so if an accessor exists and a property is defined (only possible from within the accessors setter), then the property would shadow the accessor. | ||
Line 49: | Line 76: | ||
</ | </ | ||
- | === Potential Issues | + | ==== Shadowing ==== |
- | - Decreased performance due to accessor check against any property access, could possibly be next to no impact depending on implementation (property structure with pointer to accessor structure). | + | [[https:// |
- | + | ||
- | ===== Being Debated ===== | + | Accessors will shadow properties such that if a property named $foo is declared and an accessor for $foo is declared, the accessor will be used instead, only the accessor will have direct access to the underlying property. |
- | ==== Shadowing ==== | + | <code php> |
- | v1.1 has properties shadow accessors, the suggestion is that this be inverted. | + | class TimePeriod { |
+ | private $Seconds; | ||
- | Specifically | + | public $Seconds { |
+ | get() { return $this-> | ||
+ | set($x) { $this-> | ||
+ | } | ||
+ | } | ||
- | v1.2 Proposes that this be inverted such that if there is an accessor defined for a given property name, the accessor will always be used. The accessor would be able to get/set/isset/unset the property with the same name as the accessor. No direct access to the property would be allowed except from within the accessor. | + | $o = new TimePeriod(); |
+ | $o-> | ||
+ | echo $o-> | ||
+ | </ | ||
- | v1.2 proposal seems to make the most sense however it would incur a slight (possibly *very* slight) performance penalty. | + | ==== isset / unset / attempted writes when no setter / attempted reads when no getter ==== |
+ | [[https:// | ||
+ | Invalid calls to isset/unset will fail silently and return false in the case of isset(), no warning/ | ||
+ | |||
+ | <code php> | ||
+ | class TimePeriod { | ||
+ | private $Seconds; | ||
+ | |||
+ | protected $Seconds { | ||
+ | get() { return $this-> | ||
+ | set($x) { $this-> | ||
+ | } | ||
+ | } | ||
+ | |||
+ | $o = new TimePeriod(); | ||
+ | isset($o-> | ||
+ | unset($o-> | ||
+ | </ | ||
+ | |||
+ | ==== Extra shorthand declaration ==== | ||
+ | |||
+ | Not much further support and good arguments against it, dropped. | ||
+ | |||
+ | ==== Interfaces ==== | ||
+ | [[https:// | ||
+ | |||
+ | An implementing class may specify a property with an appropriate access level to satisfy an accessor declaration requirement of an interface. | ||
+ | <code php> | ||
+ | interface i { | ||
+ | public $Seconds { get; } | ||
+ | } | ||
+ | |||
+ | class TimePeriod implements i { | ||
+ | |||
+ | /* Satisfies interface implementation requirements of interface i */ | ||
+ | public $Seconds; | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Being Debated ===== | ||
==== internal accessor method visibility / callability ==== | ==== internal accessor method visibility / callability ==== | ||
Line 86: | Line 160: | ||
Revealing these internal matters to them would only leave them confused, possibly frustrated //and likely asking about it to the internals mailing list to answer (repeatedly)// | Revealing these internal matters to them would only leave them confused, possibly frustrated //and likely asking about it to the internals mailing list to answer (repeatedly)// | ||
+ | |||
+ | ===== Issues ===== | ||
+ | |||
+ | ==== Static Accessors ==== | ||
+ | Stas pointed out a number of critical mistakes with the current implementation of static accessors. | ||
+ | - Class defined after a static accessor reference was made | ||
+ | - Dynamic variable use of an accessor --> $class:: | ||
+ | |||
+ | The current implementation " | ||
+ | |||
+ | Stas suggested that he could either help me to implement this more appropriately (such as changing the engine to make calls into zend_object_handler.c) so that these calls can be resolved dynamically, | ||
+ | |||
+ | **Update 12/ | ||
+ | ===== TODO ===== | ||
+ | - < | ||
+ | - < | ||
+ | - < | ||
+ | - < | ||
+ | - < | ||
+ | - < | ||
+ | - < | ||
+ | - < | ||
+ | - < | ||
+ | - < | ||
+ | - < | ||
+ | - < | ||
+ | - < | ||
+ | - < | ||
+ | |||
+ | ===== Previously Debated ===== | ||
==== read-only / write-only keywords ==== | ==== read-only / write-only keywords ==== | ||
Line 131: | Line 235: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | ==== Shadowing ==== | ||
+ | v1.1 has properties shadow accessors, the suggestion is that this be inverted. | ||
+ | |||
+ | Specifically this means that in v1.1, if an accessor is defined and no property is defined, then the accessor will be used. But when a property is assigned/ | ||
+ | |||
+ | v1.2 Proposes that this be inverted such that if there is an accessor defined for a given property name, the accessor will always be used. The accessor would be able to get/ | ||
+ | |||
+ | v1.2 proposal seems to make the most sense however it would incur a slight (possibly *very* slight) performance penalty. | ||
==== isset / unset / attempted writes when no setter / attempted reads when no getter ==== | ==== isset / unset / attempted writes when no setter / attempted reads when no getter ==== | ||
Line 139: | Line 252: | ||
- Let the compilation occur and at runtime when a disallowed action is attempted, emit a warning and move on. | - Let the compilation occur and at runtime when a disallowed action is attempted, emit a warning and move on. | ||
- As is currently, either at compilation or at runtime we issue a fatal error and stop execution (probably least preferable if at runtime) | - As is currently, either at compilation or at runtime we issue a fatal error and stop execution (probably least preferable if at runtime) | ||
- | |||
- | ==== Interfaces ==== | ||
- | v1.1 fully allows accessors to be defined in interfaces and requires that those accessors be defined in implementing classes. | ||
- | |||
- | === Arguments For === | ||
- | - From the outside observer of an interface, a class which defines a property has satisfied the requirement, | ||
- | |||
- | === Arguments Against === | ||
- | - Additional overhead on interface checking, would only be allowed for a non-asymmetrical accessor | ||
- | - Would give userland developers the ability to write poor code as properties are non-observable (object would not know its property was changed) | ||
==== Extra shorthand declaration ==== | ==== Extra shorthand declaration ==== | ||
Line 167: | Line 270: | ||
</ | </ | ||
- | ===== Issues ===== | + | ==== Interfaces |
+ | v1.1 fully allows accessors to be defined in interfaces and requires that those accessors be defined in implementing classes. | ||
- | ==== Static Accessors ==== | + | === Arguments For === |
- | Stas pointed out a number of critical mistakes with the current implementation of static accessors. | + | - From the outside observer |
- | - Class defined after a static accessor reference was made | + | |
- | - Dynamic variable use of an accessor --> $class::$variable = 5; | + | |
- | The current implementation " | + | === Arguments Against |
- | + | - Additional overhead on interface checking, would only be allowed for a non-asymmetrical | |
- | Stas suggested that he could either help me to implement this more appropriately (such as changing the engine to make calls into zend_object_handler.c) so that these calls can be resolved dynamically, | + | - Would give userland developers the ability to write poor code as properties |
- | + | ||
- | + | ||
- | ===== TODO ===== | + | |
- | - Exceptions thrown from an accessor | + | |
- | - get_class_methods() - hide accessors or re-write to call into Reflection* | + | |
- | - Check debug_backtrace() output | + | |
- | - Add notes to RFC on shadowing behavior of properties | + | |
- | | + | |
- | - Check that the following should work and write tests for them: | + | |
- | - $foo-> | + | |
- | - $foo-> | + | |
- | - $foobar = & | + | |
- | - $foo-> | + | |
- | - $foo-> | + | |
- | - $foo-> | + | |
- | - Expand on the "Error Messaging" | + | |
rfc/propertygetsetsyntax-as-implemented/change-requests.1350841948.txt.gz · Last modified: 2017/09/22 13:28 (external edit)