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/13 14:52]
cpriest Updated method to call parent accessor
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 through reflection +            // Due to technical limitations accessing the parent property is only possible through Reflection 
-            (new ReflectionPropertyAccessor(__CLASS__, 'Milliseconds'))->setValue($this, $value);+            (new ReflectionPropertyAccessor(get_parent_class(), 'Milliseconds'))->setValue($this, $value);
         }         }
     }     }
Line 340: Line 341:
   * unset called from illegal context: Recursion warning is emitted, unset is ignored.   * 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 ... */
 +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 ... */
 +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 */
 ==== Final Properties ==== ==== Final Properties ====
Line 405: Line 446:
     public $dataArray {     public $dataArray {
-        &get { return $this->_dataArray; }+        &get()       { return $this->_dataArray; } 
 +        set(&$value) { $this->_dataArray = $value; }
     }     }
 } }
Line 421: 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 508: 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 
 ===== Change Log ===== ===== Change Log =====
rfc/propertygetsetsyntax-v1.2.1358088750.txt.gz · Last modified: 2017/09/22 13:28 (external edit)