rfc:propertygetsetsyntax-v1.2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
rfc:propertygetsetsyntax-v1.2 [2013/01/11 17:11]
cpriest [Additions]
rfc:propertygetsetsyntax-v1.2 [2017/09/22 13:28] (current)
Line 2: Line 2:
   * Version: 1.2   * Version: 1.2
   * Created: 2012-12-29   * Created: 2012-12-29
-  * Author: Clint Priest <phpdev at zerocue dot com>+  * Updated: 2013-01-17 
 +  * Author: Clint Priest <cpriest at php dot net>
   * Contributors: Nikita Popov   * Contributors: Nikita Popov
-  * Status: Ready for Review & Discussion or Vote+  * Status: Declined, Vote Failed
  
 ==== Fork ==== ==== Fork ====
Line 136: Line 137:
         // This accessor is now public instead of protected         // This accessor is now public instead of protected
         public set {         public set {
-            // You can access a base class accessor explicitly, just like accessing a base class method +            // Due to technical limitations accessing the parent property is only possible through Reflection 
-            parent->Milliseconds = $value;+            (new ReflectionPropertyAccessor(get_parent_class(), 'Milliseconds'))->setValue($this, $value);
         }         }
     }     }
Line 304: Line 305:
  
 ==== Recursion ==== ==== Recursion ====
-Recursion with property accessors works identically to their %%__get()%% and %%__set()%% cousins in that recursion is guarded, the first call to a getter will call the accessor, a second attempt to get that property will access the underlying property directly.+Recursion with property accessors works identically to their %%__get()%% and %%__set()%% cousins in that recursion is guarded
 + 
 +When the accessor that was called attempts to access the property it will directly access the underlying property, this is the only context in which the recursion guard is bypassed.
  
 <code php> <code php>
Line 328: Line 331:
 Line  4: Directly reads the underlying property (getter is guarded from a 2nd call) Line  4: Directly reads the underlying property (getter is guarded from a 2nd call)
 Line  5: Directly reads the underlying property (getter is guarded from a 2nd call) and returns the value Line  5: Directly reads the underlying property (getter is guarded from a 2nd call) and returns the value
 +</code>
 +
 +=== Illegal Context Access (Recursion Guarding) ===
 +If an accessor is called while it is already being guarded (from recursion) from an illegal context (anything that isn't the same accessor) then the following occurs:
 +
 +  * get called from illegal context: Recursion warning is emitted, NULL is returned.
 +  * set called from illegal context: Recursion warning is emitted, set is ignored.
 +  * isset called from illegal context: Recursion warning is emitted, false is returned.
 +  * unset called from illegal context: Recursion warning is emitted, unset is ignored.
 +
 +==== Abstract Accessors ====
 +Individual accessors may be defined abstract which will cause the class to be abstract and require any extending classes to define a body for the abstract accessors.
 +
 +<code php>
 +class Foo {
 +    public $bar {
 +        abstract get;
 +    }
 +}
 +
 +class SubFoo extends Foo {
 +}
 +
 +/* Fatal error: Class Foo contains 2 abstract accessors and must be declared
 +      abstract or implement the remaining accessors (Foo::$bar->get, Foo::$bar->isset) in ... */
 +</code>
 +
 +Just like abstract functions, it is illegal to declare an accessor abstract and to provide a body:
 +<code php>
 +class Foo {
 +    public $bar {
 +        abstract get { return 'test'; }
 +    }
 +}
 +
 +/* Fatal error: Abstract function Foo::$bar->get() cannot contain body in ... */
 +</code>
 +
 +You may also declare an entire property as abstract such as:
 +
 +<code php>
 +class Foo {
 +    abstract public $bar {
 +        get;
 +    }
 +}
 +
 +/* This marks all declared accessors as abstract, as well as the class.  An extending class 
 +   would need to provide a body for any declared accessors */
 </code> </code>
  
Line 394: Line 446:
          
     public $dataArray {     public $dataArray {
-        &get { return $this->_dataArray; }+        &get()       { return $this->_dataArray; } 
 +        set(&$value) { $this->_dataArray = $value; }
     }     }
 } }
Line 410: Line 463:
   * $foobar->baz = $x with $bar being object or empty or non-object value   * $foobar->baz = $x with $bar being object or empty or non-object value
   * $foo->bar{$x} = “foo” (string offsets)   * $foo->bar{$x} = “foo” (string offsets)
-  * $foo->bar = &bar->baz; (setting either side affects the other) 
  
  
Line 497: Line 549:
 ===== Reflection ===== ===== Reflection =====
  
-==== Changes ==== 
  
-  * ReflectionClass::getProperties() will now return an array of ReflectionProperty and ReflectionPropertyAccessor classes. +==== ReflectionProperty changes ====
-  * ReflectionClass::getProperty() will also return an appropriate class based on being a property or a property with accessors.+
  
-==== Additions ====+The class has the following functions added:
  
-=== ReflectionMethodAccessor extends ReflectionMethod ===+  * getGet(): Returns a ReflectionMethod object for the getter or false if no getter is defined. 
 +  * getSet(): Returns a ReflectionMethod object for the setter or false if no setter is defined. 
 +  * getIsset(): Returns a ReflectionMethod object for the isset accessor. 
 +  * getUnset(): Returns a ReflectionMethod object for the unset accessor. 
 +  * hasAccessors(): Returns true if the property has accessors, false otherwise.
  
-  * isAutoImplemented(): Returns true if the accessor was automatically implemented (no body declared)+A fairly extensive test-suite has been created to test the functionality as well.
  
-=== ReflectionPropertyAccessor extends ReflectionProperty ===+===== Backward Compatibility ===== 
 +There are no known backward compatibility issues.
  
-The new class has all of the same functions as the ReflectionProperty as well as:+===== Internal Implementation =====
  
-  * getGet()Returns a ReflectionMethodAccessor object for the getter or false if no getter is defined. +Implementation Details Documenthttps://wiki.php.net/rfc/propertygetsetsyntax-implementation-details
-  * getSet()Returns a ReflectionMethodAccessor object for the setter or false if no setter is defined. +
-  * getIsset(): Returns a ReflectionMethodAccessor object for the isset accessor. +
-  * getUnset(): Returns a ReflectionMethodAccessor object for the unset accessor.+
  
-All other functions have been updated to return appropriate values and/or provide appropriate actions for an accessor.+===== Impact on APC and other Zend extensions =====
  
-=== Updates ===+In addition to the "implementation details document" linked in the previous section this section outlines the impact the accessors implementation has on APC and other Zend extensions.
  
-  * ReflectionClass::getProperties() returns an array of ReflectionProperty and ReflectionPropertyAccessor classes +Most Zend extensions should not be affected by this change. Accessors are normal ''zend_op_array''s, they are called as any other function and have a meaningful name. As such extensions like XDebug should not need any adjustments to support accessors.
-  * ReflectionClass::getProperty() will return either ReflectionProperty or ReflectionPropertyAccessor depending on the property requested+
  
-A fairly extensive test-suite has been created to test the functionality as well.+One extension that will require minor changes is APC. APC has to copy all ''zend_op_array''s and ''zend_property_info''s because they may be modified at runtime. Due to this proposal additional ''op_array''s may be located in  ''property_info->accs'' and need to be copied too. Here are the code snippets that need to be inserted in APC to do this: https://gist.github.com/4615156 (full code with the changes: https://gist.github.com/4597660). Other extensions that do something similar will require updates along the same lines.
  
-===== Backward Compatibility ===== +Thus the impact of the change on Zend exts is rather small.
-There are no known backward compatibility issues.+
  
-===== Internal Implementation =====+===== Tests ===== 
 +  * 2012-12-30: 67 tests at this time 
 +  * 2013-01-17: 83 tests at this time
  
-Implementation Details Document: https://wiki.php.net/rfc/propertygetsetsyntax-implementation-details+===== Voting =====
  
-===== Tests ===== +Voting ends not before Wednesday, January 23rd 2013. The PHP language is expanded, so a 2/3 majority is required. 
-  2012-12-30 : 67 tests at this time+ 
 +<doodle title="Accept PHP Accessors for 5.5?" auth="cpriest" voteType="single" closed="true"> 
 +   Yes 
 +   * No 
 +</doodle>
  
 ===== Change Log ===== ===== Change Log =====
rfc/propertygetsetsyntax-v1.2.1357924309.txt.gz · Last modified: 2017/09/22 13:28 (external edit)